【问题标题】:CursorAdapter onitemClick of listviewCursorAdapter onitem点击列表视图
【发布时间】:2013-12-14 09:06:15
【问题描述】:

您好,我正在开发一个带有 CursorAdapter 的 android 应用程序,用于加载列表视图。在 listview 项目的 onItemClick 上,我正在尝试开始对话活动。

    adapter = new ConversationAdapter(MainActivity.this, cursor);
    list.setAdapter(adapter);


    list.setOnItemClickListener(new OnItemClickListener() 
    {
        public void onItemClick(AdapterView<?> parent, View view, int position, long arg3) 
        {
            Cursor cur = (Cursor) adapter.getItem(position);
            cur.moveToPosition(position);
            id = cur.getString(cur.getColumnIndexOrThrow("_id"));

            Intent intent = new Intent(MainActivity.this, DialogueActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString ("id", id);
            intent.putExtras(bundle);

            startActivity(intent);
        }
    });

我只使用没有finish() 的startActivity。问题是要在后面显示的列表视图消失了,只有一个黑屏。不知道我需要做什么才能使列表视图显示在 DialogueActivity 的背景中。

listview项的onItemClick显示如下

ma​​in_activity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".EaseSms" >

<LinearLayout
    android:id="@+id/linearlayoutlistSMS"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".88"
    android:orientation="vertical"
    android:paddingBottom="3dp" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:divider="#000000"
        android:dividerHeight="5dp" >
    </ListView>

    <TextView
        android:id="@+id/Nosms"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="No SMS to display"
        android:textColor="#FFFFFF"
        android:textSize="28dp"
        android:textStyle="bold"
        android:visibility="gone" />
</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayoutCreateMessage"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".12"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/createmsg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/newcreatesms"
        android:gravity="center"
        android:orientation="horizontal" >
    </LinearLayout>
</LinearLayout>

dialogue_activity.xml

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

<LinearLayout
    android:id="@+id/linearLayoutdeleteall"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight=".33"
    android:background="@drawable/cal_sms_bg"
    android:gravity="center|left"
    android:orientation="vertical"
    android:paddingTop="5dp" >

    <ImageView
        android:id="@+id/edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@null"
        android:src="@drawable/newdeleteconversation"
        android:visibility="visible" />
</LinearLayout>

</LinearLayout>

请帮忙。谢谢!

【问题讨论】:

    标签: android android-listview simplecursoradapter android-cursoradapter onitemclick


    【解决方案1】:

    试试这个代码..

    getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    

    setContentView(R.layout.activity); 之前DialogueActivity.class

    【讨论】:

    • 试过了!但还是一样。一旦我单击它,列表视图就会被清除。 MainActivity 中的其他按钮仍然可见。我不确定为什么 listview 会被清除。
    • @sanjana 我检查了它。它显示正确显示您的DialogueActivity.class
    • 我能够获得对话活动,但是看不到后台的列表视图。这正是问题所在。
    • @sanjana 以图像格式向我展示。在单击 item1、item 2 列表后还可以查看我的图像,它将活动显示为对话框
    • @sanjana 尝试在 xml 中为您的列表视图提供 android:cacheColorHint="#00000000" 并还原发生的情况。
    猜你喜欢
    • 1970-01-01
    • 2012-01-03
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多