Я разрабатываю простое приложение из учебных пособий, которые я видел, и я пытаюсь просто отобразить два текстовых представления в каждой строке списка, имя и цену. Это сработало, и я мог выбрать строку, и это будет активировать намерение. Однако затем я изменил свой XML-код так, чтобы представление списка было помещено в linearLayout, чтобы у меня был заголовок в верхней части экрана. Теперь, когда я нажимаю на любую из строк, они подсвечиваются, но больше ничего не происходит. Я уже пытался установить для textviews clickable = false в xml, но все равно не повезло. Я надеюсь, что мне просто не хватает чего-то простого в методе onCreate. `открытый класс ViewMenuListing extends ListActivity {
public static final String ROW_ID = "row_id"; // Intent extra key
private ListView contactListView; // the ListActivity's ListView
private CursorAdapter contactAdapter; // adapter for ListView
private String tableName;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
contactListView = getListView(); // get the built-in ListView
contactListView.setOnItemClickListener(viewContactListener);
setContentView(R.layout.viewmenu);
//Get table name of menu clicked.
Bundle extras = getIntent().getExtras();
tableName = extras.getString("table");
// map each contact's name to a TextView in the ListView layout
String[] from = new String[] { "name", "price" };
int[] to = new int[] { R.id.itemTextView, R.id.priceTextView };
//int[] to = new int[] { R.id.itemTextView};
contactAdapter = new SimpleCursorAdapter(
ViewMenuListing.this, R.layout.menu_list_item, null, from, to);
setListAdapter(contactAdapter); // set contactView's adapter
}`
Единственное, что я изменил в этом коде, это то, что теперь я использовал setContentView (R.layout.viewmenu), когда раньше этого не делал, и список будет просто представлением содержимого.
Вот мой файл viewMenu:
`
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>`
и мой menu_list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/itemTextView"
android:padding="8dp"
android:clickable = "false"
android:textSize="20sp" android:textColor="@android:color/white"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/priceTextView"
android:clickable = "false"
android:textColor="@android:color/white"/>
</LinearLayout>
Спасибо за вашу помощь!