I am new in android development and I need to modify my code to make it show the text with image function:
print_view xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BFAF80">
<ListView
style="14dp"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:id="#+id/operations"
android:layout_below="#+id/search_view"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_below="#+id/operations"
android:layout_centerHorizontal="true"
android:src="#drawable/printer" />
list_row_item xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:padding="20dp"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_weight="1"
android:src="#drawable/wifi"
android:layout_height="wrap_content"
android:id="#+id/imageForList" />
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="35dp"
android:layout_height="wrap_content"
android:text="Nearby Wifi"
android:id="#+id/textForList" />
<ImageView
android:layout_width="match_parent"
android:layout_weight="1"
android:src="#drawable/bluetooth"
android:layout_height="wrap_content"
android:id="#+id/imageForList2" />
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="35dp"
android:layout_height="wrap_content"
android:text="Nearby Blutooth"
android:id="#+id/textForList2" />
<ImageView
android:layout_width="match_parent"
android:layout_weight="1"
android:src="#drawable/usb"
android:layout_height="wrap_content"
android:id="#+id/imageForList3" />
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="35dp"
android:layout_height="wrap_content"
android:text="Direct USB Connected"
android:id="#+id/textForList3" />
<ImageView
android:layout_width="match_parent"
android:layout_weight="1"
android:src="#drawable/cloud"
android:layout_height="wrap_content"
android:id="#+id/imageForList4" />
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="35dp"
android:layout_height="wrap_content"
android:text="Google Cloud Print"
android:id="#+id/textForList4" />
</LinearLayout>
SettingsList java class:
public class SettingsList {
private int[] images;
private String[] items;
public SettingsList(int[] images, String[] items) {
this.images = images;
this.items = items;
}
public int[] getImages() {
return images;
}
public void setImages(int[] images) {
this.images = images;
}
public String[] getItems() {
return items;
}
public void setItems(String[] items) {
this.items = items;
}
}
SettingsAdapter java class :
public class SettingsAdapter extends ArrayAdapter<SettingsList> {
public SettingsAdapter(Context context, int resource, List<SettingsList> objects) {
super(context, resource, objects);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderItems holder;
if(convertView == null){
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.list_row_item, parent, false);
holder = new ViewHolderItems();
holder.holderImage = (ImageView)convertView.findViewById(R.id.imageForList);
holder.holderImage = (ImageView)convertView.findViewById(R.id.imageForList2);
holder.holderImage = (ImageView)convertView.findViewById(R.id.imageForList3);
holder.holderImage = (ImageView)convertView.findViewById(R.id.imageForList4);
holder.holderText = (TextView)convertView.findViewById(R.id.textForList);
holder.holderText = (TextView)convertView.findViewById(R.id.textForList2);
holder.holderText = (TextView)convertView.findViewById(R.id.textForList3);
holder.holderText = (TextView)convertView.findViewById(R.id.textForList4);
convertView.setTag(holder);
}else{
holder = (ViewHolderItems)convertView.getTag();
}
SettingsList current = getItem(position);
holder.holderImage.setImageResource(current.getImages()[position]);
holder.holderText.setText(current.getItems()[position]);
return convertView;
}
static class ViewHolderItems{
ImageView holderImage;
TextView holderText;
}
}
PrintView mainactivity :
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class PrintView extends ActionBarActivity { private ListView lv;
private SettingsAdapter adapter;
private List<SettingsList> itemList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.print_view);
int[] imgs = new int[]
{
R.drawable.wifi,
R.drawable.bluetooth,
R.drawable.usb,
R.drawable.cloud,
};
String[] values = new String[]
{"Nearby Wifi",
"Nearby Blutooth",
"Direct USB Connected",
"Google Cloud Print"
};
lv = (ListView)findViewById(R.id.operations);
itemList = new ArrayList<>();
itemList.add(new SettingsList(imgs, values));
adapter = new SettingsAdapter(PrintView.this, R.layout.list_row_item, itemList);
lv.setAdapter(adapter);
}
}
Try this:
1) Create a res/layout/list_row_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:padding="20dp"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_weight="1"
android:src="#mipmap/ic_launcher"
android:layout_height="wrap_content"
android:id="#+id/imageForList" />
<TextView
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_marginTop="35dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textForList" />
</LinearLayout>
</LinearLayout>
2) Create your custom List item:
public class SettingsList {
private int image;
private String item;
public SettingsList(int image, String item) {
this.image = image;
this.item = item;
}
public int getImage() {
return image;
}
public void setImage(int image) {
this.image = image;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
}
3) Create your custom adapter
public class SettingsAdapter extends ArrayAdapter<SettingsList> {
public SettingsAdapter(Context context, int resource, List<SettingsList> objects) {
super(context, resource, objects);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderItems holder;
if(convertView == null){
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.list_row_item, parent, false);
holder = new ViewHolderItems();
holder.holderImage = (ImageView)convertView.findViewById(R.id.imageForList);
holder.holderText = (TextView)convertView.findViewById(R.id.textForList);
convertView.setTag(holder);
}else{
holder = (ViewHolderItems)convertView.getTag();
}
SettingsList current = getItem(position);
holder.holderImage.setImageResource(current.getImage());
holder.holderText.setText(current.getItem());
return convertView;
}
static class ViewHolderItems{
ImageView holderImage;
TextView holderText;
}
}
4) In your Activity that you want the listview to be shown do this:
public class YourActivity extends ActionBarActivity {
private ListView lv;
private SettingsAdapter adapter;
private List<SettingsList> itemList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView)findViewById(R.id.operations);
itemList = new ArrayList<>();
itemList.add(new SettingsList(R.drawable.wifi, Nearby Wifi));
itemList.add(new SettingsList(R.drawable.bluetooth, Nearby Blutooth));
itemList.add(new SettingsList(R.drawable.usb, Direct USB Connected));
itemList.add(new SettingsList(R.drawable.cloud, Google Cloud Print));
adapter = new SettingsAdapter(YourActivity.this, R.layout.list_row_item, itemList);
lv.setAdapter(adapter);
}
}
5) The print_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#BFAF80">
<ListView
style="14dp"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:id="#+id/operations"
android:layout_below="#+id/search_view"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Hope it helps!!!
Related
I've been trying to get a custom Recycler view adapter to work. I can't quite see why it wouldn't work. What I find strange is that the code for the custom adapter does not execute (as in it doesn't break when I put a breakpoint there) and I'm certain I bind the custom adapter to the recycler view. I hope someone can see why it doesn't work.
Activity:
public class payment_history extends AppCompatActivity {
RecyclerView list;
ArrayList<pay_item> list_data;
pay_adapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment_history);
list_data = new ArrayList<>();
list_data.add(new pay_item(10, 100, "jow", "10"));
list_data.add(new pay_item(10, 100, "joe", "10"));
list_data.add(new pay_item(10, 100, "joe", "10"));
list = findViewById(R.id.payment_history_list);
list.setLayoutManager(new LinearLayoutManager(this));
adapter = new pay_adapter(list_data);
list.setHasFixedSize(true);
list.setAdapter(adapter);
}
}
class pay_item {
int time;
double amount;
String name, table;
pay_item(int time, double amount, String name, String table) {
this.time = time;
this.amount = amount;
this.name = name;
this.table = table;
}
}
Adapter:
class pay_adapter extends RecyclerView.Adapter<pay_adapter.viewholder> {
private ArrayList<pay_item> data;
pay_adapter(ArrayList<pay_item> in) {
data = in;
}
#NonNull
#Override
public viewholder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.payment_history_item, parent, false);
return new viewholder(v);
}
#Override
public void onBindViewHolder(#NonNull viewholder holder, int position) {
holder.name.setText(data.get(position).name);
holder.table.setText(data.get(position).table);
holder.amm.setText(String.valueOf(data.get(position).amount));
holder.time.setText(data.get(position).time);
}
#Override
public int getItemCount() {
return 0;
}
static class viewholder extends RecyclerView.ViewHolder {
TextView time, amm, name, table;
viewholder(View view) {
super(view);
time = view.findViewById(R.id.pay_time);
amm = view.findViewById(R.id.pay_amount);
name = view.findViewById(R.id.pay_name);
table = view.findViewById(R.id.pay_table);
}
}
}
Row view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<TextView
android:id="#+id/pay_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Time"
android:textColor="#000000"
android:textSize="36sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/pay_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#000000"
android:textSize="24sp" />
<TextView
android:id="#+id/pay_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:text="table" />
</LinearLayout>
<TextView
android:id="#+id/pay_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:text="Amount"
android:textColor="#color/colorPrimary"
android:textSize="36sp" />
</LinearLayout>
Layout with recycler view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".payment_history">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/payment_history_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Any help is appreciated.
Two things
pay_adapter(ArrayList<pay_item> in) {
data = in;
}
#Override
public int getItemCount() {
return data.size() ;
}
Good night android masters. Please help me. maybe those of you who understand better than me can help me solve the problem I'm facing right now.
1 https://imgur.com/S2TU08q
I made a listview on the fragment. I stopped because I was confused how I proceeded. maybe the code below can help you solve my problem!
This is the fragment I made. I name it Frag_Tour.java
public class Frag_Tour extends Fragment {
ListView listView;
ListViewAdapterTour adapter;
String[] judul1;
String[] judul2;
String[] durasi;
String[] harga;
int[] gambarTour;
ArrayList<Model> arrayList = new ArrayList<Model>();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.frag_tour, container, false);
judul1 = new String[]{"Paket Hemat", "Paket Reguler", "Paket Honeymoon"};
judul2 = new String[]{"Wisata Belitung", "Wisata Belitung", "Wisata Belitung"};
durasi = new String[]{"3 Hari 2 Malam", "4 Hari 3 Malam", "3 Hari 1 Malam"};
harga = new String[]{"Rp 750.000/pax", "Rp 750.000/pax", "Rp 750.000/pax"};
gambarTour = new int[]{
R.drawable.mercusuar_1, R.drawable.mercusuar_2, R.drawable.mercusuar_3
};
listView = rootView.findViewById(R.id.listView);
for (int i = 0; i < judul1.length; i++) {
Model model = new Model(judul1[i], judul2[i], durasi[i], harga[i], gambarTour[i]);
arrayList.add(model);
}
adapter = new ListViewAdapterTour(this, arrayList);
listView.setAdapter((ListAdapter) arrayList);
return rootView;
}
}
this is the xml file. frag_tour.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parent_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
[2] https://imgur.com/ehPanZM
this is the ListViewAdapter that I have created. I named it ListViewAdapterTour.java
public class ListViewAdapterTour extends BaseAdapter {
Context mContext;
LayoutInflater inflater;
List<Model> modellist;
ArrayList<Model> arrayList;
public ListViewAdapterTour (Context context, List<Model> modellist) {
mContext = context;
this.modellist = modellist;
inflater = LayoutInflater.from(mContext);
this.arrayList = new ArrayList<Model>();
this.arrayList.addAll(modellist);
}
public class ViewHolder {
TextView Judul1, Judul2, Durasi, Harga;
ImageView GambarTour;
}
#Override
public int getCount() {
return modellist.size();
}
#Override
public Object getItem(int i) {
return modellist.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(final int position, View view, ViewGroup parent) {
ViewHolder holder;
if (view==null){
holder = new ViewHolder();
view = inflater.inflate(R.layout.row_tour, null);
holder.Judul1 = view.findViewById(R.id.judul1);
holder.Judul2 = view.findViewById(R.id.judul2);
holder.Durasi = view.findViewById(R.id.durasi);
holder.Harga = view.findViewById(R.id.harga);
holder.GambarTour = view.findViewById(R.id.GambarTour);
view.setTag(holder);
}
else {
holder = (ViewHolder)view.getTag();
}
holder.Judul1.setText(modellist.get(position).getJudul1());
holder.Judul2.setText(modellist.get(position).getJudul2());
holder.Durasi.setText(modellist.get(position).getDurasi());
holder.Harga.setText(modellist.get(position).getHarga());
holder.GambarTour.setImageResource(modellist.get(position).getGambartour());
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (modellist.get(position).getJudul1().equals("Paket Hemat 3 Hari 2 Malam")){
Intent intent = new Intent(mContext, TourDetail.class);
intent.putExtra("contentTv","PAKET HEMAT");
mContext.startActivity(intent);
}
}
});
return view;
}
}
and this is the xml file. row_tour.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:focusableInTouchMode="true"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="#dimen/spacing_middle"
android:layout_weight="1"
app:cardCornerRadius="2dp"
app:cardElevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:orientation="vertical">
<ImageView
android:id="#+id/GambarTour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="#drawable/mercusuar_1"
tools:ignore="ContentDescription" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/overlay_dark_20" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#id/GambarTour"
android:layout_margin="#dimen/spacing_medium"
android:orientation="vertical"
tools:ignore="UselessParent">
<TextView
android:id="#+id/judul1"
style="#style/TextAppearance.AppCompat.Large"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Paket Hemat"
android:textColor="#color/White"
android:textStyle="bold" />
<TextView
android:id="#+id/judul2"
style="#style/TextAppearance.AppCompat.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wisata Belitung"
android:textColor="#color/White"
android:textStyle="bold" />
<TextView
android:id="#+id/durasi"
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/_3_hari_2_malam"
android:textColor="#color/White" />
</LinearLayout>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignEnd="#id/GambarTour"
android:layout_alignRight="#id/GambarTour"
android:layout_margin="#dimen/spacing_medium"
android:src="#drawable/ic_favorite_border"
android:tint="#color/White" />
<TextView
android:id="#+id/harga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#id/GambarTour"
android:layout_alignRight="#id/GambarTour"
android:layout_alignBottom="#id/GambarTour"
android:layout_margin="#dimen/spacing_large"
android:background="#drawable/gradient_green"
android:padding="#dimen/spacing_xmedium"
android:text="Rp 750.000/pax"
android:textColor="#color/White" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
[3] https://imgur.com/h7WiBgK
and this is the code for the model.java that I use
package com.androidrion.sejengkalapp;
class Model {
private String judul1;
private String judul2;
private String durasi;
private String harga;
private int gambartour;
//constructor
Model(String judul1, String judul2, String durasi, String harga, int gambartour) {
this.judul1 = judul1;
this.judul2 = judul2;
this.durasi = durasi;
this.harga = harga;
this.gambartour = gambartour;
}
//getters
String getJudul1() {
return this.judul1;
}
String getJudul2() {
return this.judul2;
}
String getDurasi() {
return this.durasi;
}
String getHarga() {
return this.harga;
}
int getGambartour() {
return this.gambartour;
}
}
I hope the teachers and masters about Android can help me in solving this problem. what I want is row_tour.xml which I have designed to be listview in frag_tour.xml
[4] https://imgur.com/VLzOUiK
The context should be the activity holding the fragment. So instead of this in your adapter constructor, use getActivity()
adapter = new ListViewAdapterTour(getActivity(), arrayList);
I use fragment and I want to set listview in m fragment.I have error in this field.
I want to use ListView of Foldingcell, but I think I have an error in my adapter.
i can not find error.
any body can't help me?
what should I do?
this is my error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at com.a700daneh.a700daneh.loanFragment.onCreateView(loanFragment.java:49)
this is my element for using in listView
public class Item {
String family1;
String cost1;
String family2;
String cost2;
String explain;
String code;
int Icon;
private View.OnClickListener requestBtnClickListener;
public Item() {
}
public Item(String family1, String cost1, String family2, String cost2, String explain, String code, int Icon) {
this.family1 = family1;
this.cost1 = cost1;
this.family2 = family2;
this.cost2 = cost2;
this.explain = explain;
this.code = code;
this.Icon = Icon;
//this.time = time;
}
public String getFamily1() {
return family1;
}
public void setFamily1(String family1) {
this.family1 = family1;
}
public String getCost1() {
return cost2;
}
public void setCost1(String cost2) {
this.cost2 = cost2;
}
public String getFamily2() {
return family2;
}
public void setFamily2() {
this.family2 = family2;
}
public String getCost2() {
return cost2;
}
public void setCost2() {
this.cost2 = cost2;
}
public String getExplain() {
return explain;
}
public void setExplain() {
this.explain = explain;
}
public String getCode() {
return code;
}
public void setCode() {
this.code = code;
}
public int getIcon() {
return Icon;
}
/**
* #return List of elements prepared for tests
*/
public static ArrayList<Item> getTestingList() {
ArrayList<Item> items = new ArrayList<>();
items.add(new Item("خانواده x:", "500,000 تومان", "خانواده x:", "500,000 تومان", "توضیحات:", "کد: 12345678", R.drawable.family));
items.add(new Item("خانواده x:", "500,000 تومان", "خانواده x:", "500,000 تومان", "توضیحات:", "کد: 12345678", R.drawable.family));
items.add(new Item("خانواده x:", "500,000 تومان", "خانواده x:", "500,000 تومان", "توضیحات:", "کد: 12345678", R.drawable.family));
items.add(new Item("خانواده x:", "500,000 تومان", "خانواده x:", "500,000 تومان", "توضیحات:", "کد: 12345678", R.drawable.family));
items.add(new Item("خانواده x:", "500,000 تومان", "خانواده x:", "500,000 تومان", "توضیحات:", "کد: 12345678", R.drawable.family));
return items;
}
}
this is my adapter called FoldingCellListAdapter
public class FoldingCellListAdapter extends ArrayAdapter<Item> {
private HashSet<Integer> unfoldedIndexes = new HashSet<>();
private View.OnClickListener defaultRequestBtnClickListener;
public FoldingCellListAdapter(Context context, List<Item> objects) {
super(context, 0, objects);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// get item for selected view
Item item = getItem(position);
// if cell is exists - reuse it, if not - create the new one from resource
FoldingCell cell = (FoldingCell) convertView;
ViewHolder viewHolder;
if (cell == null) {
viewHolder = new ViewHolder();
LayoutInflater vi = LayoutInflater.from(getContext());
cell = (FoldingCell) vi.inflate(R.layout.cell, parent, false);
// binding view parts to view holder
viewHolder.family1 = (TextView) cell.findViewById(R.id.family1);
viewHolder.code = (TextView) cell.findViewById(R.id.code);
viewHolder.family2 = (TextView) cell.findViewById(R.id.family2);
viewHolder.cost2 = (TextView) cell.findViewById(R.id.cost2);
viewHolder.explain = (TextView) cell.findViewById(R.id.explain);
viewHolder.cost1 = (TextView) cell.findViewById(R.id.cost1);
viewHolder.payment = (TextView) cell.findViewById(R.id.pay);
viewHolder.familyImage1 = (ImageView) cell.findViewById(R.id.familyImage1);
viewHolder.pinkback = (ImageView) cell.findViewById(R.id.pinkback);
viewHolder.familyImage2 = (ImageView) cell.findViewById(R.id.familyImage2);
cell.setTag(viewHolder);
} else {
// for existing cell set valid valid state(without animation)
if (unfoldedIndexes.contains(position)) {
cell.unfold(true);
} else {
cell.fold(true);
}
viewHolder = (ViewHolder) cell.getTag();
}
// bind data from selected element to view through view holder
viewHolder.family1.setText(item.getFamily1());
//viewHolder.time.setText(item.getTime());
viewHolder.code.setText(item.getCode());
viewHolder.family2.setText(item.getFamily2());
viewHolder.cost2.setText(item.getCost2());
viewHolder.explain.setText(String.valueOf(item.getExplain()));
viewHolder.cost1.setText(item.getCost1());
viewHolder.familyImage1.setImageResource(item.getIcon());
viewHolder.familyImage2.setImageResource(item.getIcon());
viewHolder.pinkback.setImageResource(item.getIcon());
return cell;
}
// simple methods for register cell state changes
public void registerToggle(int position) {
if (unfoldedIndexes.contains(position))
registerFold(position);
else
registerUnfold(position);
}
public void registerFold(int position) {
unfoldedIndexes.remove(position);
}
public void registerUnfold(int position) {
unfoldedIndexes.add(position);
}
// View lookup cache
private static class ViewHolder {
TextView family1;
TextView payment;
TextView cost1;
TextView family2;
TextView cost2;
TextView explain;
TextView code;
ImageView familyImage1;
ImageView pinkback;
ImageView familyImage2;
}
}
this is my codes in loanFragment
public class loanFragment extends Fragment {
public loanFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.cell, container, false);
ListView lvlist = (ListView) view.findViewById(R.id.lvlist);
final ArrayList<Item> items = Item.getTestingList();
// create custom adapter that holds elements and their state (we need hold a id's of unfolded elements for reusable elements)
final FoldingCellListAdapter adapter = new FoldingCellListAdapter(getContext(), items);
// set elements to adapter
lvlist.setAdapter(adapter);
// set on click event listener to list view
lvlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
// toggle clicked cell state
((FoldingCell) view).toggle(false);
// register in adapter that state for selected cell is toggled
adapter.registerToggle(pos);
}
});
return view;
}
}
I had a layout called cell_content_layout for foldingcell and another layout called cell_title_layout and include these layouts in one layout called cell.
cell_title_content
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="#+id/cell_title_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/cell_content_view"
android:layout_toRightOf="#+id/cell_content_view">
<FrameLayout
android:id="#+id/familyFrame"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#dd0f70">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp" />
<ImageView
android:id="#+id/familyImage1"
app:srcCompat="#drawable/family"
android:layout_width="100dp"
android:layout_height="109dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:visibility="visible" />
</FrameLayout>
<FrameLayout
android:id="#+id/textFrame1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d3d8dd">
<LinearLayout
android:id="#+id/textLinear1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/family1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="18dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="۱. خانواده x"
android:textSize="18dp" />
<TextView
android:id="#+id/cost1"
android:layout_width="match_parent"
android:layout_height="51dp"
android:layout_marginRight="18dp"
android:gravity="center_vertical"
android:text="۵۰۰,۰۰۰ تومان"
android:textSize="18dp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
cell_content_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="#+id/cell_content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#ffffff"
android:orientation="vertical"
>
<FrameLayout
android:id="#+id/textFrame2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#d3d8dd">
<ImageView
android:id="#+id/pinkback"
android:layout_width="100dp"
android:layout_height="109dp"
android:layout_alignParentBottom="true"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#dd0f70"
android:visibility="visible" />
<ImageView
android:id="#+id/familyImage2"
android:layout_width="100dp"
android:layout_height="109dp"
android:layout_alignParentBottom="true"
android:layout_gravity="left"
android:layout_weight="1"
android:visibility="visible"
app:srcCompat="#drawable/family" />
<LinearLayout
android:id="#+id/textLinear2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
<TextView
android:id="#+id/family2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="18dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="۱. خانواده x"
android:textSize="18dp" />
<TextView
android:id="#+id/cost2"
android:layout_width="match_parent"
android:layout_height="51dp"
android:layout_marginRight="18dp"
android:gravity="center_vertical"
android:text="۵۰۰,۰۰۰ تومان"
android:textSize="18dp" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/containFrame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"></LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/frameContent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical">
<TextView
android:id="#+id/explain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginRight="18dp"
android:layout_marginTop="15dp"
android:layout_weight="1.00"
android:gravity="right"
android:text="توضیحات:" />
<TextView
android:id="#+id/code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="18dp"
android:layout_weight="0.99"
android:gravity="right"
android:text="کد: ۱۲۳۴۵۶۷۸۹" />
<Button
android:id="#+id/pay"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="#drawable/button_style2"
android:text="پرداخت"
android:textColor="#color/white"
android:textSize="16dp" />
</LinearLayout>
</FrameLayout>
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>
cell
<?xml version="1.0" encoding="utf-8"?>
<com.ramotion.foldingcell.FoldingCell
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/folding_cell_main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:clipChildren="false"
android:clipToPadding="false">
<include
android:id="#+id/include"
layout="#layout/cell_content_layout"
android:visibility="gone" />
<include
layout="#layout/cell_title_layout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/include" />
</com.ramotion.foldingcell.FoldingCell>
It looks like your error is in the setAdapter not the onItemClickListener.
My guess is that ListView lvlist = (ListView) view.findViewById(R.id.lvlist); return null;
Check if "R.id.lvlist" is realy the id of your listView in the xml file.
Also, Check if "lvlist" is null after the findViewById line of code
I'm implementing View-pager in List-view as row item .When run the application my images is not scrolling one by one in view pager. What is the wrong in my code. Can someone suggest me how to make it work or scrolling smoothly images in view pager.
Here is my code
public class Demo_Display extends Activity {
private String str[] = {"weklfjo","??2","??3"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView)findViewById(R.id.listview);
MyListAdapter adapter = new MyListAdapter(this,R.layout.row,str);
listView.setAdapter(adapter);
}
class MyListAdapter extends ArrayAdapter<String> {
private LayoutInflater inflater = null;
private static final float BUTTON_WIDTH_DP = 70f;
private int margin;
public MyListAdapter(Context context, int resource,String[] items) {
super(context, resource,items);
inflater = LayoutInflater.from(context);
float density = getContext().getResources().getDisplayMetrics().density;
int buttonWidthPX = (int) (BUTTON_WIDTH_DP * density + 0.5f);
WindowManager wm = (WindowManager)getContext().getSystemService(getContext().WINDOW_SERVICE);
Display dp = wm.getDefaultDisplay();
margin = dp.getWidth() - buttonWidthPX;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = inflater.inflate(R.layout.row,null);
}
ViewPager viewPager = (ViewPager)convertView.findViewById(R.id.Image_ViewPagers);
viewPager.setPageMargin(-margin);
// MyPagerAdapter adapter = new MyPagerAdapter(getContext(),getItem(position));
MyPagerAdapter adapter = new MyPagerAdapter(getContext());
viewPager.setAdapter(adapter);
return convertView;
}
}
class MyPagerAdapter extends PagerAdapter {
Context mContent;
LayoutInflater mLayoutInflater;
private int[] GalImages = new int[] {
R.drawable.flower1,
R.drawable.flower1
};
public MyPagerAdapter(Context context) {
super();
mContent = context;
mLayoutInflater = (LayoutInflater) mContent.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public Object instantiateItem(ViewGroup container, int position)
{
ImageView imageView = new ImageView(mContent);
int padding = mContent.getResources().getDimensionPixelSize(R.dimen.abc_button_padding_horizontal_material);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
#Override
public int getCount() {
// return PAGE_NUM;
return GalImages.length;
}
#Override
public boolean isViewFromObject(View view, Object obj) {
//return view.equals(obj);
return view == ((ImageView) obj);
}
}
}
Here is my XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txt_InitialLetter"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/circle_shape"
android:gravity="center"
android:paddingBottom="5sp"
android:text="jsdygf" />
<TextView
android:id="#+id/txt_Desc"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal|left"
android:paddingLeft="5sp"
android:text="sdkjhfeorygdshgvfsjd" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:orientation="horizontal"
android:paddingLeft="5sp" >
<android.support.v4.view.ViewPager
android:id="#+id/Image_ViewPagers"
android:layout_width="fill_parent"
android:layout_height="190dp"
android:background="#android:color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="4dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/reply_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/retweet_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/star" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/camera_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/recorder_blue" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:src="#drawable/follow_up" />
</LinearLayout>
</LinearLayout>
and List View xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
I've been spending a few hours on a problem and I still can't figure it out. The setOnClickListener in HotelOverviewFragment is not firing when I click an item in my ListView. However, the setOnClickListener does work from my custom adapter (NowArrayAdapter).
My question is: why the setOnClickListener not working in HotelOverviewFragment (Class where the ListView is shown)?
Here's a list of what I've tried:
Setting android:focusable="false", android:focusableInTouchMode="false", android:descendantFocusability="blocksDescendants" in the hotel_row_layout.xml and fragment_hotel_overview.xml.
Setting android:clickable on true and false. Both didn't work.
Changing from BaseAdapter implementation to arrayAdapter.
I tried different listeners in HotelOverviewFragment: setOnClickListener, setOnItemClickListener, setOnItemSelectedListener and setOnTouchListener. Unfortunately, none of those worked for me.
Here's my code:
Custom adapter
public class NowArrayAdapter extends ArrayAdapter<String> {
private Context context;
private ArrayList<String> values;
private Typeface typeface;
private static Hashtable fontCache = new Hashtable();
private LayoutInflater inflater;
private TextView item;
public NowArrayAdapter(Context context, ArrayList<String> commandsList) {
super(context, R.layout.hotel_row_layout, commandsList);
this.context = context;
values = new ArrayList<String>();
values.addAll(commandsList);
typeface = getTypeface(this.context, "fonts/Roboto-Light.ttf");
inflater = LayoutInflater.from(this.context);
}
static Typeface getTypeface(Context context, String font) {
Typeface typeface = (Typeface)fontCache.get(font);
if (typeface == null) {
typeface = Typeface.createFromAsset(context.getAssets(), font);
fontCache.put(font, typeface);
}
return typeface;
}
public View getView(int position, View convertView, ViewGroup parent) {
String myText = getItem(position);
if(convertView == null) {
convertView = inflater.inflate(R.layout.hotel_row_layout, parent, false);
item = (TextView) convertView.findViewById(R.id.maps_button);
item.setTypeface(typeface);
convertView.setTag(item);
} else {
item = (TextView) convertView.getTag();
}
item.setText(myText);
//myListItem.descText.setTextSize(14);
convertView.setOnClickListener(new View.OnClickListener() {
// WORKS!
#Override
public void onClick(View view) {
Log.d("click", "Don't look at me!");
}
});
return convertView;
}
}
Fragment
public class HotelOverviewFragment extends Fragment {
private static Hashtable fontCache = new Hashtable();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_hotel_overview, container, false);
ListView list = (ListView) v.findViewById(android.R.id.list);
// Set up listview and buttons
setUp(v, list);
// Inflate the layout for this fragment
return v;
}
static Typeface getTypeface(Context context, String font) {
Typeface typeface = (Typeface)fontCache.get(font);
if (typeface == null) {
typeface = Typeface.createFromAsset(context.getAssets(), font);
fontCache.put(font, typeface);
}
return typeface;
}
public void setUp(View v, ListView l){
TextView address = (TextView) v.findViewById(R.id.content);
TextView header = (TextView) v.findViewById(R.id.header);
TextView hotelName = (TextView) v.findViewById(R.id.hotelName);
Typeface typeface = getTypeface(getActivity(), "fonts/Roboto-Light.ttf");
address.setText("some street \nZipCode, City \nCountry \nEmail \nphoneNumber");
address.setTypeface(typeface);
header.setText("Hotel info");
header.setTypeface(typeface);
header.setTextSize(20);
hotelName.setText("Hotel name");
hotelName.setTypeface(typeface);
// Set up button
ArrayList<String> n = new ArrayList<String>();
n.add(0, "More info");
// Show button
NowArrayAdapter adapter = new NowArrayAdapter(getActivity(), n);
l.setAdapter(adapter);
// THIS IS THE STUFF I'VE BEEN TRYING
try {
l.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("click", "Success");
}
});
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("click", "Success");
}
});
l.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.d("click", "Success");
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
l.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("click", "Success");
return false;
}
});
}catch (Exception e){
Log.d("click", e + "");
}
}
}
Layout xml of HotelOverviewFragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.example"
android:background="#ffebebeb">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:src="#drawable/banner"
android:id="#+id/hotelBanner"
android:layout_gravity="top"
android:adjustViewBounds="false"
android:scaleType="fitXY" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Hotelname"
android:id="#+id/hotelName"
android:gravity="center"
android:textSize="40dp"
android:layout_alignBottom="#+id/hotelBanner"
android:layout_alignParentRight="false"
android:layout_alignParentLeft="false"
android:textColor="#ffc4c4c4"
android:layout_marginBottom="5dp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp"
android:background="#drawable/header_card">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/header"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#android:color/primary_text_light"
android:layout_height="wrap_content"
android:text="Header"
android:layout_toRightOf="#+id/headerImage"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/headerImage"
android:src="#drawable/ic_action_live_help"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:background="#drawable/content_card">
<TextView
android:id="#+id/content"
android:layout_gravity="left|center_vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textColor="#android:color/primary_text_light"
android:layout_height="wrap_content"
android:text="Content"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
The custom xml for a listview item
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="#drawable/content_card">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/maps_button"
android:layout_gravity="left|center_vertical"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#android:color/primary_text_light"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
<ImageView
android:src="#drawable/ic_action_arrow_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentTop="false"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="false"
android:layout_centerVertical="true"
/>
</RelativeLayout>
</LinearLayout>
Thanks in advance.
Thanks to Daniel Nugent's suggestion I got it working. Removing the convertView.setOnClickListener() is part of the answer. I think it was blocking the other listeners in the HotelOverviewFragment.
My next mistake was that I used setOnClickListener on a ListView for testing.
setOnClickListener should be used for buttons not ListViews.
So after removing setOnClickListener all the other listeners started working.
Thanks for your time.