0

我正在使用光标适配器来获取自定义列表视图。我有两个 xml 文件。

a.xml 有一个LinearlayoutwithListview

y.xml 有Linearlayout两个Textview.

当我看到列表视图时,我无法选择。我正在使用setOnItemClickListener从列表视图中选择一个项目。

我试图搜索这个并知道他们中的许多人都有同样的问题。我尝试将它应用于 xml 中的 textviewandroid:focusable="false和编程方式。

这个问题的解决方法是什么?

一个.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           />

               <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
           />
     </LinearLayout>
    </ScrollView>

y.xml

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>
4

3 回答 3

0

也许这个问题是这样的:button in expandable listview android

试试这个:

mTextView.setFocuseable(false);

在你的 .java 类而不是你的 xml 中。

于 2012-09-17T12:35:09.033 回答
0

看看这个,希望它能给你一些指导,不幸的是,如果没有看到你的整个 java 就不能做很多事情!:

public class CRUDonDB extends ListActivity {

private final String SAMPLE_DB_NAME = "myFriendsDb";
private final String SAMPLE_TABLE_NAME = "friends";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ListView lv = getListView();

    ArrayList<String> results = new ArrayList<String>();
    SQLiteDatabase sampleDB = null;

    try {
        sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);

        sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                SAMPLE_TABLE_NAME +
                " (LastName VARCHAR, FirstName VARCHAR," +
                " Country VARCHAR, Age INT(3));");

        sampleDB.execSQL("INSERT INTO " +
                SAMPLE_TABLE_NAME +
                " Values ('Doe','John','UK',22);");
        sampleDB.execSQL("INSERT INTO " +
                SAMPLE_TABLE_NAME +
                " Values ('Smith','Robert','UK',20);");
        sampleDB.execSQL("INSERT INTO " +
                SAMPLE_TABLE_NAME +
                " Values ('Walton','Henry','UK',10);");

        Cursor c = sampleDB.rawQuery("SELECT FirstName, LastName, Country, Age FROM " +
                SAMPLE_TABLE_NAME +
                " where Age >= 10 LIMIT 5", null);

        if (c != null ) {
            if  (c.moveToFirst()) {
                do {
                    String firstName = c.getString(c.getColumnIndex("FirstName"));
                    String lastName = c.getString(c.getColumnIndex("LastName"));
                    String country = c.getString(c.getColumnIndex("Country"));
                    int age = c.getInt(c.getColumnIndex("Age"));
                    results.add("" + firstName + " " + lastName + " " + country + " " +age);
                }while (c.moveToNext());
            } 
        }

        this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));

        lv
        .setOnItemClickListener(mOnItemListViewClickListener);


    } catch (SQLiteException se ) {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database");
    } finally {
        if (sampleDB != null) 
            sampleDB.execSQL("DELETE FROM " + SAMPLE_TABLE_NAME);
            sampleDB.close();
    }
}

private final OnItemClickListener mOnItemListViewClickListener = new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {

        String item = (String) parent.getItemAtPosition(position);
        Toast.makeText(getBaseContext(), "You have chosen " +item, Toast.LENGTH_LONG).show();
};
};

}
于 2012-09-17T14:37:39.173 回答
0

删除<scrollview>,它就像一个魅力。

于 2012-09-21T17:56:02.717 回答