我正在使用CWAC MergeAdapter - https://github.com/commonsguy/cwac-merge在ListView
中添加两个数据适配器。像这样:
MergeAdapter mergeAdapter = new MergeAdapter();
mergeAdapter.addAdapter(yourFirstAdapter);
mergeAdapter.addAdapter(yourSecondAdapter);
list.setAdapter(mergeAdapter);
我还为ListView
设置了一个项目点击监听器。但是我想要的是只有来自adapter1的数据才可以点击。我该如何实现呢。到目前为止我所拥有的是:
ListView list = (ListView) findViewById(R.id.lv);
RelativeLayout secondAdapterlistRowLayout = (RelativeLayout) findViewById(R.id.secondrow);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long mallId) {
//go to the shops view
if (adapterView.equals(secondAdapterlistRowLayout)){
//do nothing
}
else {
Intent intent = new Intent(getActivity(), ShopActivity.class);
intent.putExtra("MALL_ID", (int) mallId);
startActivity(intent);
}
}
});
XML - row2 - adapter2
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0F0F0"
android:clickable="false"
android:id="@+id/secondrow">
....
</RelativeLayout>
基本上我想这样做:
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long mallId) {
if(R.id.secondrow is clicked){ then start a new activity }
}
}
答案 0 :(得分:1)
我找到的更简单的方法是获取被点击的资源名称,然后将其与行的资源名称(即secondrow)进行比较
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long mallId) {
if (getResources().getResourceEntryName(view.getId()).equals("secondrow"){
//then do something
}
//otherwise do nothing
}
}
答案 1 :(得分:0)
在适配器视图中,对项目使用setTag()方法,并在点击listview任何项目时识别该标记。