I want to add button to each row of my listview. I created an XML file called row.xml in my layout folder and added two textviews and a button in that file. But when a button is added, I am unable to click the item of listview. I'm only able to click the button. Here is row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/text11"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#000000"
/>
<TextView
android:id="#+id/text2"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:textColor="#000000"
/>
<Button android:text="Button" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
I want to refer to textviews and button in my activity. Please help me and suggest some ideas.
I had a similar issue. The simple trick is to add android:focusable="false" to your Button.
You can use a custom adapter (extending an array adapter is fairly simple). In the getView method, set a onClickListener on your TextView, this way both your button and the other parts of the ListItem will respond to touch.
you must add focusable="false" and you can
<Button
android:id="#+id/bt_do"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
**android:focusable="false"** />
in your adapter
public class MyAdapter extends BaseAdapter {
private Context context;
private List< Objet > objects;
private OnClickListener listener;
public MyAdapter(Context context, List<Objet> objects,
OnClickListener listener) {
this.context = context;
this.objects = objects;
this.listener = listener;
// TODO Auto-generated constructor stub
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = ((Activity) context)
.getLayoutInflater();
convertView = infalInflater.inflate(R.layout.my_line_list, null);
}
Button bt_do=(Button)convertView.findViewById(R.id.bt_do);
bt_do.setOnClickListener(listener);
return convertView;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return objects.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return objects.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
and in your activity create un adapter and implement listener of button.
Related
My listview has three textview and one checkbox in horizontal order.
My listview xml code
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="TEXT"
android:id="#+id/textView1"
android:textSize="20sp"
android:gravity="center"
android:layout_weight="5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="TEXT"
android:id="#+id/textView2"
android:textSize="20sp"
android:gravity="center"
android:layout_weight="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="TEXT"
android:id="#+id/textView3"
android:textSize="20sp"
android:gravity="center"
android:layout_weight="5" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/checkBox1"
android:focusable="false"
android:clickable="false"
android:layout_gravity="right"
android:layout_marginRight="10dp"/>
and MainActivity.java code
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView,
View view, int position, long id) {
Object vo = (Object)adapterView.getAdapter().getItem(position);
Log.d(TAG, String.valueOf(vo));
}
});
The log output for String.valueOf(vo) is
sn.studyroom.ListViewItem#f085546
How can I get each of the three Textview values?
If you catch the clicked object right, you must convert it to TextView, and then get your TextView's text like this:
String vo = ((TextView)adapterView.getAdapter().getItem(position)).getText().toString();
Log.d(TAG, vo);
OR
Go your adapter class and create an interface to get clicked item's values.
You can use adapter for accessing your text fields and check box. Pass your list to a adapter like this:
CustomListAdapter adapter = new CustomListAdapter (context, yourList);
yourListView.setAdapter(adapter);
Create an adapter like this.
public class CustomListAdapter extends BaseAdapter {
Context context;
List<ListObject> yourList;
public CustomListAdapter (Context context, List<ListObject> yourList) {
this.context = context;
this.yourList= yourList;
}
public void refreshAdapter(List<ListObject> yourList){
this.yourList= yourList;
notifyDataSetChanged();
}
private static class ViewHolder {
TextView textView1, textView2, textView3;
CheckBox checkBox1;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return yourList.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return yourList.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.your_adapter_layout, null);
holder = new ViewHolder();
holder.textView1= convertView.findViewById(R.id.textView1);
holder.textView2= convertView.findViewById(R.id.textView2);
holder.textView3= convertView.findViewById(R.id.textView3);
holder.checkBox1= convertView.findViewById(R.id.checkBox1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//TODO: you can do whatever you want to do here
return convertView;
}
}
If you want to retrive list data then i want to know about to set data. Are you set model and add in adapter or taking static string arraylist? so let me know then i will suggest better way to do that.
in my App i have a Navigation Drawer, the ListView of the NavigatinDrawer' has anImageView,TextViewand anotherTextViewwith idtv_navDrawerOptionDescription`as shown below.
the number of items in the ListView of the navigation drawer are three items (eco-assist, data-logger-exit) each of them has ImageView, TextView"as title" and another TextView" as description"
what i want to do is, when the drawer is opened, all the "description TextView" of three items i have in the NavigationDrawer ListView should be rotation horizontally forever as marquee.
when i run the App. i found the description textview is static and not rotating
my attempts are posted belwo
the layout of the listview of the navigationDrawer
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_selector">
<ImageView
android:id="#+id/iv_navDrawerOptionImage"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="#string/desc_list_item_icon"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/tv_navDrawerOptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/iv_navDrawerOptionImage"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#color/list_item_title"
android:gravity="center_vertical"/>
<TextView
android:id="#+id/tv_navDrawerOptionDescription"
android:layout_below="#id/tv_navDrawerOptionTitle"
android:singleLine="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
NavigationDrawer ListAdapter:
public class NavDrawerListAdapter extends BaseAdapter{
private Context context;
private ArrayList<NavDrawerModell> navDrawerModel;
public NavDrawerListAdapter(Context context, ArrayList<NavDrawerModell> navDrawerModell) {
// TODO Auto-generated constructor stub
this.context = context;
this.navDrawerModel = navDrawerModell;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return this.navDrawerModel.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return this.navDrawerModel.get(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
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.drawer_list_layout, null);
}
ImageView iv_Icon = (ImageView) convertView.findViewById(R.id.iv_navDrawerOptionImage);
TextView tv_Title = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionTitle);
TextView tv_Desc = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionDescription);
iv_Icon.setImageResource(navDrawerModel.get(position).getIcon());
tv_Title.setText(navDrawerModel.get(position).gettitle());
tv_Desc.setText(navDrawerModel.get(position).getDescription());
return convertView;
}
}
<TextView
android:id="#+id/tv_navDrawerOptionDescription"
android:layout_below="#id/tv_navDrawerOptionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true">
Please try the above code and see if this works.
EDIT:
In getView function of the subclasses BaseAdapter add the following code:
tv_Desc.setText(navDrawerModel.get(position).getDescription());
tv_Desc.setSelected(true);
tv_Desc.requestFocus();
I am trying to create a master/detail flow application on Android 4.2.
I have created a master detail flow project, but I want to implement an ExpandableListView instead of the ListView that is provided.
The master/detail uses fragments, and here’s where I am stuck… I have successfully created an expandable list view in a separate project. How can I implement it inside a master/detail flow?
I assume you used the IDE wizard to create the Master/Detail example project. If this is so, then you probably saw that the wizard created an ItemListFragment class which by default extends ListFragment.
If you need to replace the simple list with an expandable one, then you'll have to:
Extend from Fragment, instead of ListFragment
Create an xml layout file where you declare an ExpandableListView
Override onCreateView() and inflate the layout that contains the ExpandableListView
Get a reference to the ExpandableListView, and then use it as you did before.
Something like this:
// extend from Fragment
public class ItemListFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// inflate the layout that contains the ExpandableListView
View view = inflater.inflate(R.layout.fragment_items_list, container, false);
// get a reference to ExpandableListView
ExpandableListView list = (ExpandableListView)view.findViewById(R.id.my_list);
// set the adapter
// set listeners
return view;
}
}
I have no idea how to create ExpandableListView, but you can achieve with custom listview like I implemented in my Project
1. Create Custom list row
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000" >
<RelativeLayout
android:id="#+id/rel_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:layout_marginTop="17dp"
android:layout_toLeftOf="#+id/imageView1"
android:paddingBottom="15dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#685f56" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/text1"
android:layout_marginRight="16dp"
android:layout_marginTop="5dp"
android:src="#drawable/highlight_icon" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rel_main"
android:visibility="gone" >
</RelativeLayout>
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout1"
android:background="#685f56" />
</RelativeLayout>
**2. Create Custom Adapter in "ItemListFragment.java" **
public class CustomAdepeterNewJob extends BaseAdapter{
//String[] tablecontent;
int Click=0;
Map<String, DummyItem> tablecontent = new HashMap<String, DummyItem>();
Context context;
public CustomAdepeterNewJob(Context context, Map<String, DummyItem> titles)
{
this.context = context;
this.tablecontent = titles;
}
public class ViewHolder {
public TextView txt;
public ImageView img;
public RelativeLayout relativeLayout1,rel_main;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return tablecontent.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = convertView;
final ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
view = inflater.inflate(R.layout.c_simple_list_item, parent, false);
holder = new ViewHolder();
holder.txt = (TextView) view.findViewById(R.id.text1);
holder.img = (ImageView) view.findViewById(R.id.imageView1);
holder.rel_main=(RelativeLayout) view.findViewById(R.id.rel_main);
holder.relativeLayout1=(RelativeLayout) view.findViewById(R.id.relativeLayout1);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
String s=DummyContent.ITEMS.get(position).content;
System.out.println("==dummy "+s);
holder.txt.setText(s);
if (s.equalsIgnoreCase("All"))
{
holder.img.setImageResource(R.drawable.all_icon);
}else if (s.equalsIgnoreCase("Note")) {
holder.img.setImageResource(R.drawable.notes_icon);
}else if (s.equalsIgnoreCase("Highlight")) {
holder.img.setImageResource(R.drawable.highlight_icon);
}else if (s.equalsIgnoreCase("Snapshots")) {
holder.img.setImageResource(R.drawable.snapshot_icon);
}else if (s.equalsIgnoreCase("Draw")) {
holder.img.setImageResource(R.drawable.draw_icon);
}else if (s.equalsIgnoreCase("Record Sounde")) {
holder.img.setImageResource(R.drawable.sound_recorder_icon);
}
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id);
if (holder.relativeLayout1.getVisibility()==View.GONE)
{
holder.rel_main.setBackgroundResource(R.drawable.list_item_bg_pressed);
holder.relativeLayout1.setVisibility(View.VISIBLE);
}else {
holder.relativeLayout1.setVisibility(View.GONE);
holder.rel_main.setBackgroundColor(Color.TRANSPARENT);
}
}
});
return view;
}
}
3. And ad Custom Adapter in "onCreate" in ItemListFregment
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: replace with a real list adapter.
/*setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
R.layout.c_simple_list_item, R.id.text1, DummyContent.ITEMS));*/
setListAdapter(new CustomAdepeterNewJob(getActivity(), DummyContent.ITEM_MAP));
}
I want to implement a grid Adapter that receives an ArrayList of Element2S, where Element2S is a custom object with two String (Element2S(String a, String b)
The GridAdapter should use the Element2S ArrayList to populate the Grid.
the first String of Element2S object should be the first column element, the second String of Element2S the second element
My GridAdapter is:
public class GridViewAdapterC2 extends BaseAdapter {
private ArrayList<Element2S> itemList;
private Activity activity;
public GridViewAdapterC2(Activity activity,
ArrayList<Element2S> itemList) {
super();
this.itemList = itemList;
this.activity = activity;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return itemList.size();
}
#Override
public Element2S getItem(int position) {
// TODO Auto-generated method stub
return itemList.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public static class ViewHolder {
public TextView txtViewColumn1;
public TextView txtViewColumn2;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder view;
LayoutInflater inflator = activity.getLayoutInflater();
if (convertView == null) {
view = new ViewHolder();
convertView = inflator.inflate(R.layout.grid_row_2c, null);
view.txtViewColumn1 = (TextView) convertView
.findViewById(R.id.col1);
view.txtViewColumn2 = (TextView) convertView
.findViewById(R.id.col2);
convertView.setTag(view);
} else {
view = (ViewHolder) convertView.getTag();
}
String textCoilumn1 = itemList.get(position).getA();
String textCoilumn2 = itemList.get(position).getB();
view.txtViewColumn1.setText(textCoilumn1);
view.txtViewColumn2.setText(textCoilumn2);
return convertView;
}
}
Unfortunately when in the main I try to use this adapter with
gridAdapter = new GridViewAdapterC2(this, myItemArrayList);
mygrid= (GridView) findViewById(R.id.myGridView);
mygrid.setAdapter(gridAdapter);
The result is wrong.
My gridRow layout is
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:layout_gravity="left">
<TextView
android:id="#+id/col1"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="left|start"
android:padding="5dp"
android:textColor="#color/light_sky"
android:textSize="12sp" />
<TextView
android:id="#+id/col2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="left|start"
android:padding="5dp"
android:textColor="#color/green_2"
android:textSize="12sp" >
</TextView>
</TableRow>
</TableLayout>
The myGridView layout in the main activity is
<GridView
android:id="#+id/myGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:gravity="center_horizontal"
android:numColumns="2" >
</GridView>
I cannot figure what is wrong.
If my Elements2S arraylist is
1st element2S: (1,23a)
2nd element2S: (2,15b)
3rd element2S: (3,22c)
The Grid shows
1 2
3
But the right output is
1 23a
2 15b
3 22c
I think the ListView is better than GridView in this situation.
And I think the LinearLayout is better than TableLayout.
Your output is wrong because some region of your grid's cell is covered by others. Try to resize your cell and grid.
This may not be the correct approach, if there is a better way pleas tell me.
I've created a class of Custom Adapter & in my getView method I inflate the view I want to use
public View getView(int position, View convertView, ViewGroup parent)
{
View v = mInflater.inflate(R.layout.wherelayout, null);
if (convertView != null)
{
v = convertView;
}
HashMap<String, Object> whereHash = (HashMap<String, Object>) this.getItem(position);
if (whereHash != null)
{
TextView whereId = (TextView) v.findViewById(R.id.tvWhere);
TextView whereDetails = (TextView) v.findViewById(R.id.tvWhereDetails);
ImageButton ibDelWhere = (ImageButton) v.findViewById(R.id.ibDelWhere);
whereId.setText((CharSequence) whereHash.get("where"));
whereDetails.setText((CharSequence) whereHash.get("details"));
if (ibDelWhere != null)
{
ibDelWhere.setId(position);
ibDelWhere.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
//do stuff when clicked
}
}
);
}
}
return v;
}
The view consists of 2 TextView aligned to the left & an ImageButton aligned to the right, I want to be able to delete the item from the ListView when the button is clicked. the layout is like this -
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal" android:clickable="true">
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="25sp" android:id="#+id/tvWhere" android:textColor="#00FF00" android:text="TextView" android:gravity="top|left" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></TextView>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/tvWhereDetails" android:textColor="#0000FF" android:text="TextView" android:textSize="18sp" android:layout_below="#+id/tvWhere" android:gravity="bottom|left" android:layout_alignParentLeft="true"></TextView>
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="#drawable/eraser" android:id="#+id/ibDelWhere" android:layout_alignParentRight="true" android:layout_alignParentTop="true"></ImageButton>
</RelativeLayout>
The problem is that when the ImageButton is in the layout, I can click it & the onClick() fires as expected, but I can't click the actual list item itself, i.e. click on the TextView items to fire the ListView.onItemClick that was assigned to it already. If I remove the ImageButton from the layout, then the ListView.onItemClick event fires when I click the item. Is there any way I can enable clicking both the ListView item & the button within the layout ?
Thanks guys & gals.
You have to set the imagebutton as non focusable and non focusableInTouchMode (clickable is ok).
Please note, as opposed as other views, you can't do that in xml because the android:focusable gets overwritten in ImageButton's constructor.
To be more precise, that's one of the few differences between ImageView and ImageButton. See for yourself, this is the complete source of ImageButton.
#RemoteView
public class ImageButton extends ImageView {
public ImageButton(Context context) {
this(context, null);
}
public ImageButton(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.imageButtonStyle);
}
public ImageButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setFocusable(true);
}
#Override
protected boolean onSetAlpha(int alpha) {
return false;
}
}
To solve, just call setFocusable(false) from java. Or use an ImageView :)
myImageButton.setFocusable(false);
Hope it helps.
You can make both clickable, but it's not really supported and Romain Guy will yell at you. Also, you won't be able to focus/press the button with the trackball. With that said, you can add the following properties to the button, which should make both clickable:
android:focusable="false"
android:focusableInTouchMode="false"
Just make sure you can live with the consequences.
Try to set
android:clickable="false" on the relative Layout.
I had the same problem with a LinearLayout inside another Linearlayout.
The outer LinearLayout was clickable=true, result:
The ListView.OnItemClickListener does not fire.
After setting it to clickable=false it works.
i.e. click on the TextView items to fire the ListView.onItemClick that was assigned to it already.
What happens when you click on the TextView while the ImageButton is there? Does it register a click on the button? or do nothing at all?
How much space in the row does the ImageButton take up? It could be that it is large enough that you can't click in the row outside of it.
I had this same problem. My solution was to set the onClick method for the view inside the adapter instead of using onItemClick.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null){
LayoutInflater inflater = context.getLayoutInflater();
v = inflater.inflate(R.layout.list_item, parent, false);
}
v.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//This should replace the onListItemClick method
}
});
v.findViewById(R.id.someinnerview).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//Write one of these for each of your inner views
}
});
return v;
}
Hope that helps! Depending on the rest of your program, this might force you into handing more data to the adapter (which I had to do) but it works.
here is example of the custom adapter in list view.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5dip">
<ImageView
android:layout_width="50dip"
android:layout_height="50dip"
android:id="#+id/imgViewLogo"
android:src="#drawable/icon"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:scaleType="center">
</ImageView>
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_width="wrap_content"
android:id="#+id/txtViewTitle"
android:layout_toRightOf="#+id/imgViewLogo"
android:layout_marginLeft="2dip">
</TextView>
<TextView
android:layout_height="wrap_content"
android:text="TextView"
android:layout_width="wrap_content"
android:id="#+id/txtViewDescription"
android:layout_toRightOf="#+id/imgViewLogo"
android:layout_below="#+id/txtViewTitle"
android:layout_marginLeft="2dip">
</TextView>
<TextView
android:layout_height="wrap_content"
android:text="TextView"
android:layout_width="wrap_content"
android:id="#+id/txtViewMobile"
android:layout_toRightOf="#+id/imgViewLogo"
android:layout_below="#+id/txtViewDescription"
android:layout_marginLeft="2dip">
</TextView>
and make java file On The BaseAdapter
public class ListViewCustomAdapter extends BaseAdapter {
Context context;
String[] mobile;
String[] month;
String[] number;
public LayoutInflater inflater;
public ListViewCustomAdapter(Context context,String[] month, String[] number, String[] mobile) {
// TODO Auto-generated constructor stub
super();
this.context = context;
this.month=month;
this.number=number;
this.mobile=mobile;
Log.i("88888888888888888","*******333********");
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
//ADC71C 95AA1F
public int getCount() {
// TODO Auto-generated method stub
return month.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
private class ViewHolder {
TextView txtViewTitle;
ImageView imgViewLogo;
TextView txtViewDescription;
TextView txtViewMobile;
}
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
Log.i("88888888888888888","*******444********");
ViewHolder holder;
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
if (convertView == null)
{
Log.i("88888888888888888","*******555********");
convertView = inflater.inflate(R.layout.listitem_row, null);
holder = new ViewHolder();
holder.imgViewLogo = (ImageView) convertView.findViewById(R.id.imgViewLogo);
holder.txtViewTitle = (TextView) convertView.findViewById(R.id.txtViewTitle);
holder.txtViewDescription = (TextView) convertView.findViewById(R.id.txtViewDescription);
holder.txtViewMobile = (TextView) convertView.findViewById(R.id.txtViewMobile);
convertView.setTag(holder);
}
else
{
Log.i("88888888888888888","*******666********");
holder = (ViewHolder) convertView.getTag();
}
Log.i("888888888888","Display the value of the textbox like(9856321584)other wise (TextView)");
holder.txtViewTitle.setText(month[position]);
holder.txtViewDescription.setText(number[position]);
holder.txtViewMobile.setText(mobile[position]);
return convertView;
}
}