<LinearLayout android:id="@+id/concontainer"
android:orientation="horizontal"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center_horizontal"
>
<ImageView android:id="@+id/comment"
android:src="@drawable/comment"
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
/>
<TextView android:id="@+id/commentnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dip"
android:layout_marginLeft="2dip"
android:layout_marginTop="5dip"
/>
</LinearLayout> public View.OnClickListener comment_click = new View.OnClickListener(){
@Override
public void onClick(View v)
{
AlertDialog.Builder builder;
AlertDialog alertDialog;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog, null);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
ViewGroup cvp = (ViewGroup)v.getParent();
final TextView goodsnum = (TextView)cvp.findViewById(R.id.commentnum);
……
builder.setPositiveButton(R.string.commit_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
…………
try
{
JSONObject jsobj = new JSONObject(strResult);
JSONObject obj = jsobj.getJSONObject("data");
goodsnum.setText(obj.getString("commentsnum") + SCConstants.COMMENTSNUM);
}
catch (JSONException e)
{
e.printStackTrace();
}
Toast.makeText(mContext, value,
Toast.LENGTH_SHORT).show();
}
}); builder.setNegativeButton(R.string.comment_cancl,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
});
alertDialog = builder.create();
alertDialog.show();
}
};
上面的xml中的代码是listview中的一个item片段点击comment 弹出alertdialog 确定后 需要改变commentnum的值ViewGroup cvp = (ViewGroup)v.getParent();
final TextView goodsnum = (TextView)cvp.findViewById(R.id.commentnum);看起来是没有获取到commentnum对象 求解
OnItemClickListener 是点击每个item的事件 另外listview 里面是根据position 确定哪个item里面的元素的操作被触发的
int visEnd = listMusic.getLastVisiblePosition();
TextView tvTitle, tvSinger, tvTextt;
int index = MusicService.mPlayPosition - visStart;
if ( index >= 0 && index <= visEnd - visStart) {
tvTitle = (TextView)(listMusic.getChildAt(index).findViewById(R.id.ItemTitle));
tvTitle.setTextColor(libraryMusicTitleFontColor);
tvSinger = (TextView)(listMusic.getChildAt(index).findViewById(R.id.ItemSinger));
tvSinger.setTextColor(libraryArtistFontColor);
tvTextt = (TextView)(listMusic.getChildAt(index).findViewById(R.id.ItemTime));
tvTextt.setTextColor(libraryArtistFontColor);
}
这是我用到的listView中的点击item时取得item中textView的代码,根据ListView中可见区域的第一项和当前点击的item在整个list中的实际索引值,计算出显示点击项目的相对索引,就可以取得你要的TextView了。