2017-10-13 118 views
0

我有一個自定義listview其中包含buttontextviewtextview知名度消失了。當button文本是「電子郵件」,並且如果我點擊buttontextview應該顯示在button的下面。但最後的textview總是變得可見。下面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從定製adapter。那麼當button點擊特定的行時,如何才能製作textviewvisbile

+0

你需要改變'viewholder.mdisplayemail.setVisibility();'to viewholder.mdisplayemail.setVisibility(View.VISIBLE);' – UltimateDevil

+0

讓我看看你的佈局? –

+0

@ user2269164檢查我的答案可能會解決您的問題 – UltimateDevil

回答

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

你需要檢查的位置和需要VISIBLEtextView喜歡 - :

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; 
} 
+0

@ user2269164試試這個會有幫助 – UltimateDevil

+0

@ user2269164你試過這個 – UltimateDevil

+0

謝謝你的工作。 – user2269164

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); 

      } 
+0

@UltimateDevil - 它將啓用最後一行中的textview,而不是我點擊的那個。 – user2269164

+0

是的,等我回復 – UltimateDevil

相關問題