Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>here is simple example how to hide image from list view. first try to understand this code after that modify your code.</strong> </p> <p><img src="https://i.stack.imgur.com/CVvAm.png" alt="enter image description here"></p> <p>i have listview with text &amp; image.</p> <p>here is row file of list view <code>my_spinner_style.xml</code>.</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="horizontal" android:weightSum="2" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/ic_launcher" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>my activity class:</p> <pre><code>package com.example.testapp; import android.app.ListActivity; import android.content.Context; import android.os.Bundle; import android.text.Html; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class MainActivity extends ListActivity { private static final String[] COUNTRIES = new String[] { "Belgium", "France", "Italy" }; private static final Integer[] img = new Integer[] { R.drawable.ic_launcher, R.drawable.dhaval1, R.drawable.ic_launcher }; private MyArrayAdapter adapter; Bundle savedInstanceState; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); adapter = new MyArrayAdapter(MainActivity.this); getListView().setAdapter(adapter); } private class MyArrayAdapter extends BaseAdapter { private LayoutInflater mInflater; public MyArrayAdapter(Context con) { // TODO Auto-generated constructor stub mInflater = LayoutInflater.from(con); } @Override public int getCount() { // TODO Auto-generated method stub return COUNTRIES.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub final ListContent holder; View v = convertView; if (v == null) { v = mInflater.inflate(R.layout.my_spinner_style, null); holder = new ListContent(); holder.name = (TextView) v.findViewById(R.id.textView1); holder.name2 = (ImageView) v.findViewById(R.id.imageView1); v.setTag(holder); } else { holder = (ListContent) v.getTag(); } holder.name.setText("" + Html.fromHtml("" + COUNTRIES[position])); holder.name2.setImageDrawable(getResources().getDrawable( img[position])); holder.name.setOnClickListener(mOnTitleClickListener3); return v; } } static class ListContent { TextView name; ImageView name2; } public OnClickListener mOnTitleClickListener3 = new OnClickListener() { public void onClick(View v) { final int position = getListView().getPositionForView( (View) v.getParent()); View rowView = getListView().getChildAt(position); if (rowView != null) { // do whatever you want here View mainv = ((ViewGroup) rowView).getChildAt(1); Log.e("select dd---&gt;", "" + mainv); // hide Image from here.... mainv.setVisibility(View.GONE); } } }; protected void onRestart() { // adapter.notifyDataSetChanged(); onCreate(savedInstanceState); }; } </code></pre> <p><strong>I have addd <code>OnClickListener</code> on <code>TextView</code> insted of that you can use your perent layout. im my case is <code>LinearLayout</code>.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload