我有一个自定义listview
,其中包含button
和textview
。 textview
知名度已消失。当button
文字是"电子邮件"如果我点击button
,textview
应显示在button
下方。但最后textview
始终可见。
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
wantedUsers du = wusers.get(i);
final String mcontact = du.mcontact;
if(view==null) {
viewholder = new viewholder();
view = LayoutInflater.from(ws).inflate(R.layout.wantedmoviecustom, null);
viewholder.mcontwcustom = (Button)view.findViewById(R.id.mcontwcustom);
viewholder.mdisplayemail = (TextView) view.findViewById(R.id.mdisplayemail);
view.setTag(viewholder);
} else {
viewholder = (viewholder) view.getTag();
}
viewholder.mdisplayemail.setVisibility(View.GONE);
if(mcontact.contains("@")) {
viewholder.mcontwcustom.setText("Show Email");
viewholder.mdisplayemail.setText(mcontact);
} else {
viewholder.mcontwcustom.setText("Call");
}
viewholder.mcontwcustom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mcontact.contains("@")) {
int p=(Integer)view.getTag();
viewholder.mdisplayemail.setVisibility(View.VISIBLE);
// viewholder.mdisplayemail.setText(mcontact);
}
else
{
Uri call = Uri.parse("tel:" + mcontact);
Intent surf = new Intent(Intent.ACTION_DIAL, call);
ws.startActivity(surf);
}
}
});
viewholder.mcontwcustom.setTag(i);
return view;
}
下面的来自自定义getview
的{{1}}。那么当adapter
点击特定行时,如何制作textview
visbile
。
答案 0 :(得分:1)
首先,您需要创建全局变量
int positionOfButtonClick = -1;
然后您需要在button
点击时更新您的位置,并且需要致电notifyDataSetChanged();
喜欢 - :
viewholder.mcontwcustom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
positionOfButtonClick = i;
notifyDataSetChanged();
//your other code
});
然后,在 getView
中您需要检查位置并需要VISIBLE
textView
喜欢 - :
if(i==positionOfButtonClick ){
viewholder.mdisplayemail.setVisibility(View.VISIBLE);
}
现在,您的 getView 应为 - :
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
wantedUsers du = wusers.get(i);
final String mcontact = du.mcontact;
if(view==null) {
viewholder = new viewholder();
view = LayoutInflater.from(ws).inflate(R.layout.wantedmoviecustom, null);
viewholder.mcontwcustom = (Button)view.findViewById(R.id.mcontwcustom);
viewholder.mdisplayemail = (TextView) view.findViewById(R.id.mdisplayemail);
if(i==positionOfButtonClick ){
viewholder.mdisplayemail.setVisibility(View.VISIBLE);
}else{
viewholder.mdisplayemail.setVisibility(View.GONE);
}
view.setTag(viewholder);
} else {
viewholder = (viewholder) view.getTag();
}
if(mcontact.contains("@")) {
viewholder.mcontwcustom.setText("Show Email");
viewholder.mdisplayemail.setText(mcontact);
} else {
viewholder.mcontwcustom.setText("Call");
}
viewholder.mcontwcustom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mcontact.contains("@")) {
int p=(Integer)view.getTag();
positionOfButtonClick = i;
notifyDataSetChanged();
}
else
{
Uri call = Uri.parse("tel:" + mcontact);
Intent surf = new Intent(Intent.ACTION_DIAL, call);
ws.startActivity(surf);
}
}
});
viewholder.mcontwcustom.setTag(i);
return view;
}
答案 1 :(得分:0)
如下所述更改代码,我认为它对您有帮助。
viewholder.mcontwcustom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(mcontact.contains("@")) {
int p=(Integer)view.getTag();
viewholder.mdisplayemail.setVisibility(View.VISIBLE);
// viewholder.mdisplayemail.setText(mcontact);
}