2
I have a Listview, and a layout of the Adapter item that follows its basic image
Problem is that when I click on any area of the item, in the list, every component is "selected"
I would like to get the Action 1, Action 2 and Description effect separately.
For example:
XML layout:
...
<LinearLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayout"
android:layout_marginLeft="3dp">
<!--descrição-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:id="@+id/txtDescricao"
android:text="Descricao" />
<!--este é o "separador" horizontal-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal">
<!--Tentei colocar um Linear Layout "fora" e marcar clickable = true -->
<LinearLayout android:layout_width="wrap_content"
android:layout_weight="50"
android:clickable="true"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/txtAcao1"
android:text="Acao 1" />
</LinearLayout>
<!--este é o "separador" vertical entre ação 1 e ação 2-->
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:gravity="center"
android:id="@+id/txtAcao2"
android:text="Acao 2" />
</LinearLayout>
</LinearLayout>
I also tried to add a setOnClickListener
in Action 1 and Action2, but it didn’t work
Follows the class . java
//ViewHolder
static class ViewHolderItem {
public TextView txtAcao1;
public TextView txtAcao2;
public View txtDescricao;
}
//Adapter
class RoteiroAdapter extends BaseAdapter{
private Context mContext = null;
private List<ItemRoteiro> mListaRoteiro = null;
public RoteiroAdapter(Context context, List<ItemRoteiro> lista){
this.mContext = context;
this.mListaRoteiro = lista;
}
@Override
public int getCount() {
return mListaRoteiro.size();
}
@Override
public Object getItem(int position) {
return mListaRoteiro.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderItem viewHolder;
if(convertView == null){
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(R.layout.item_roteiro, parent, false);
viewHolder = new ViewHolderItem();
viewHolder.txtAcao1= (TextView) convertView.findViewById(R.id.txtAcao1);
viewHolder.txtAcao2= (TextView) convertView.findViewById(R.id.txtAcao2);
convertView.setTag(viewHolder);
}
else{
viewHolder = (ViewHolderItem) convertView.getTag();
}
ItemRoteiro item = mListaRoteiro.get(position);
if(item != null) {
viewHolder.txtAcao1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
return convertView;
}
}
Does anyone know how to get this effect??
Thank you!!
How do you treat it in Activity?
– Reginaldo Rigo
instance each layout(are 2 actions; therefore 2 different layouts) and gives clickListener in layout.
– Mr_Anderson
@Reginaldorigo edited and posted the Activity code
– Marco Giovanni
@Mr_anderson, thanks for your help, I’ll test here and let you know the result..
– Marco Giovanni
@Mr_anderson didn’t work either.. I’ve done many tests I haven’t had any success...
– Marco Giovanni
Strange, because if it’s a custom list, then it should work, just like a cardview that contains an image with some buttons inside...
– Mr_Anderson