我有一个带有TextView的listView和另一个与该listView对应的水平listView。现在我需要为水平listview.i中的列表项编写onclick事件。无法获取父列表项位置(垂直列表视图位置)。请帮助我。提前致谢。 //垂直的第一个列表视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@null" />
</RelativeLayout>
//Adapter Getview for first list
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_item, null);
TextView title = (TextView) convertView.findViewById(R.id.title);
title.setText(mArrayList.get(position).getSite());
typeId = mArrayList.get(position).getTypeId();
hori_view = (TwoWayView) convertView.findViewById(R.id.hor_list);
mChildList = mArrayList.get(position).getChildArrList();
HorizontalAdapter horListAdapter = new HorizontalAdapter(mContext, R.layout.hori_list,mChildList);
hori_view.setAdapter(horListAdapter);
horListAdapter.notifyDataSetChanged();
hori_view.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
mChildList = mArrayList.get(position).getChildArrList(); // Here i need parent list position
String text = mChildList.get(position).getChannel().toString();
int cId = mChildList.get(position).getChannelId();
int pen = mChildList.get(position).getPending();
int typeId = mChildList.get(position).getSiteid();
Intent intent = new Intent(mContext,ChannelDetails.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle bundle = new Bundle();
bundle.putString("channel", text);
bundle.putInt("typeId", typeId);
intent.putExtras(bundle);
mContext.startActivity(intent);
}
});
return convertView;
}
//水平视图的第二个列表
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Title"
android:paddingTop="10dp"
android:paddingLeft="15dp"
android:textColor="#000000"
android:textStyle="bold"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="10dp">
<org.lucasr.twowayview.TwoWayView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/hor_list"
style="@style/TwoWayView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
tools:context=".MainActivity" />
</LinearLayout>
</LinearLayout>
//第二个列表的第二个适配器(水平列表)
public View getView(int position, View convertView, ViewGroup parent)
{
View retval = null;
if(retval == null)
{
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
retval = mInflater.inflate(this.resource, null);
holder = new Holder();
}
holder.image = (ImageView) retval.findViewById(R.id.image);
holder.pending = (TextView) retval.findViewById(R.id.textOne);
holder.channel = (TextView) retval.findViewById(R.id.text1);
holder.chan_id = (TextView) retval.findViewById(R.id.text2);
holder.text3 = (TextView) retval.findViewById(R.id.text3);
mChannel = mChildList.get(position).getChannel();
holder.channel.setText(mChannel);
holder.pending.setText(String.valueOf(mChildList.get(position).getPending()));
holder.chan_id.setText(String.valueOf(mChildList.get(position).getChannelId()));
if(mChildList.get(position).getSiteid() == 100)
{
holder.image.setBackgroundResource(R.drawable.fb_icon1);
holder.text3.setText("facebook");
}
else if(mChildList.get(position).getSiteid() == 200)
{
holder.image.setBackgroundResource(R.drawable.tr_icon1);
holder.text3.setText("twitter");
}
else if(mChildList.get(position).getSiteid() == 300)
{
holder.image.setBackgroundResource(R.drawable.in_icon1);
holder.text3.setText("linkedin");
}
retval.setTag(holder);
return retval;
}
}