Android:无法单击每行只有一个textview的ListView

时间:2014-01-04 08:26:34

标签: android listview android-listview textview

我无法点击列表中的任何项目。我的活动延伸ListActivity,我已实施OnItemClickListener并将其设置为列表。我已经研究了错误,人们在listView中有多个观点存在类似的问题,因此将focusable设为false或android:descendantFocusability="blocksDescendants" ..通常会解决他们的问题..我的问题不是得到解决。

     protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     movieListView = getListView(); // get the built-in ListView
     movieListView.setOnItemClickListener(viewMovieListener); 

     movieListView.setClickable(true);

     String[] from = new String[] { "name" };
     int[] to = new int[] { R.id.categoryTextView };
     movieAdapter = new SimpleCursorAdapter( MovieList.this, R.layout.activity_movie_list, null, from, to);

     value = getIntent().getIntExtra(MainActivity.CATEGORY, -1);
     if(value == 1)
         category = "Family";
     else if(value == 2)
         category = "Horror";
     else if(value == 3)
         category = "Comedy";

}


 OnItemClickListener viewMovieListener = new OnItemClickListener() 
   {
      @Override
      // This doesnt get called? no it doesnt
      public void onItemClick(AdapterView<?> arg0, View arg1, int position,
         long id) 
      {
         // create an Intent to launch the ViewContact Activity
         Intent viewMovie = 
            new Intent(MovieList.this, ViewMovie.class);

         // pass the selected contact's row ID as an extra with the Intent
         viewMovie.putExtra(ROW_ID, id);
         startActivity(viewMovie); // start the ViewContact Activity
      } 
   };

我的xml:

     <?xml version="1.0" encoding="utf-8"?>
     <TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/categoryTextView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="TextView"
      android:focusable = "false"
      android:descendantFocusability="blocksDescendants"
      android:clickable="true"
      ></TextView>

2 个答案:

答案 0 :(得分:0)

在ListActivity中,您可以覆盖onListItemClick以单击Item

 @Override
 public void onListItemClick(ListView l, View v, int position, long id) {
     Log.i("example",position);

 }

答案 1 :(得分:0)

试试这个

    android:focusable="false"
    android:focusableInTouchMode="false"