【发布时间】:2017-10-31 21:59:46
【问题描述】:
我有一个列表视图,其中包含通过其他活动添加到其中的项目。我的目标是在特定列表视图项目被点击时,它会启动一个特定于所点击项目的对话框。
这是列表视图
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ListView
android:id="@+id/inventoryListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:headerDividersEnabled="true"
android:onClick="f">
</ListView>
</LinearLayout>
</LinearLayout>]
这是使用适配器的活动
public class inventory extends AppCompatActivity {
public static ArrayList<String> items;
public static ArrayAdapter<String> adapter;
public static ListView inventoryListView;
SharedPreferences sharedPreferences;
protected void onCreate(Bundle savedInstanceSate){
super.onCreate(savedInstanceSate);
setContentView(R.layout.inventory);
inventoryListView = (ListView)findViewById(R.id.inventoryListView);
items = new ArrayList<String>();
adapter = new ArrayAdapter<String>(this,R.layout.inventory_list_view,items);
inventoryListView.setAdapter(adapter);
sharedPreferences = getSharedPreferences("my_prefs", 0);
updateInventory();
adapter.notifyDataSetChanged();
}
该列表未填充,因为它只能通过其他活动填充,而不是包含列表视图的活动。
【问题讨论】:
标签: android string listview adapter onclicklistener