this is my adapter, the getView method is not called even if the array list having elements
public class CarrierSammuryAdapter extends ArrayAdapter<CarrierSummary> {
private final Activity context;
private final ArrayList<CarrierSummary> ite;
private final int lay;
public CarrierSammuryAdapter(Activity context, ArrayList<CarrierSummary> menuLinkList,int layout) {
super(context,layout );
this.context = context;
this.ite = menuLinkList;
this.lay=layout;
}
// static to save the reference to the outer class and to avoid access to
// any members of the containing class
static class ViewHolder {
public TextView customer;
public TextView attempts;
public TextView successful;
public TextView minutes;
public TextView ASR;
public TextView ACD;
public TextView NER;
public TextView PDD;
}
#Override
public int getCount () {
return ite.size();
}
#Override
public long getItemId (int position) {
return position;
}
#Override
public CarrierSummary getItem (int position) {
return ite.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder will buffer the assess to the individual fields of the row layout
final ViewHolder holder;
// Recycle existing view if passed as parameter
// This will save memory and time on Android
// This only works if the base layout for all classes are the same
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();//this gives error !!
rowView=inflater.inflate(R.layout.carriersumamry_item,parent,false);
holder = new ViewHolder();
holder.customer=(TextView)rowView.findViewById(R.id.customer);
holder.attempts=(TextView)rowView.findViewById(R.id.attempts);
holder.successful=(TextView)rowView.findViewById(R.id.successful);
holder.minutes=(TextView)rowView.findViewById(R.id.minutes);
holder.ASR=(TextView)rowView.findViewById(R.id.asr);
holder.ACD=(TextView)rowView.findViewById(R.id.acd);
holder.NER=(TextView)rowView.findViewById(R.id.ner);
holder.PDD=(TextView)rowView.findViewById(R.id.pdd);
// ViewResizing.setListRowTextResizing(rowView, context);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
holder.customer.setText(ite.get(position).getCustomer());
holder.attempts.setText(ite.get(position).getAttempts());
holder.successful.setText(ite.get(position).getSuccessful());
holder.minutes.setText(ite.get(position).getMinutes());
holder.ASR.setText(ite.get(position).getASR());
holder.ACD.setText(ite.get(position).getACD());
holder.NER.setText(ite.get(position).getNER());
holder.PDD.setText(ite.get(position).getPDD());
return rowView;
}
}
and this is how i called it
carrierSummaryList =(ListView)findViewById(R.id.carrierSummary_listview);
CarrierSammuryAdapter adapter = new CarrierSammuryAdapter(CarrierSummaryActivity.this, carriersam,R.layout.carriersumamry_item);
carrierSummaryList.setAdapter(adapter);
I search a lot to solve this issue but no solution, getView method is never called.
this is my XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pdd"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ner"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/acd"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/asr"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/minutes"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/successful"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/attempts"
android:textColor="#color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/customer"
android:textColor="#color/grey"
/>
</LinearLayout>
I had this exact same problem, to solve it, I simply changed the ArrayAdapter to BaseAdapter, implemented the overriden methods and it worked.
And as khuskal said, you should always use Context instead of Activity.
there are two mistakes..
first is change Activity to Contex in constructor
secondly change
rowView=inflater.inflate(R.layout.single_row,parent,false);
Hope this will help you
/**
* Constructor
*
* #param context The current context.
* #param resource The resource ID for a layout file containing a TextView to use when
* instantiating views.
*/
public ArrayAdapter(Context context, int resource) {
init(context, resource, 0, new ArrayList<T>());
}
while you are doing super(context,layout) , this is the constructor that gets called. So adapter data is set to empty list.
Like derek said, Instead you should use super(context,layout,menuLinkList);
/**
* Constructor
*
* #param context The current context.
* #param resource The resource ID for a layout file containing a TextView to use when
* instantiating views.
* #param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, int resource, List<T> objects) {
init(context, resource, 0, objects);
}
The problem was in my drawerLayout, i put the listView into RelativeLayout but when i change to LinearLayout its working, this is the code
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:orientation="vertical">
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/mainbar"
layout="#layout/second_topmain"/>
<ListView
android:id="#+id/carrierSummary_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
></ListView>
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="0dp"
android:id="#+id/mainbar"
layout="#layout/bottom_bar"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearSlider"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:background="#7e7e7e"
android:orientation ="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Carrier Type"
android:textColor="#android:color/white"
android:padding="5dp"
android:background="#color/darkgrey"
/>
<LinearLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:background="#color/darkgrey"
android:layout_height="wrap_content">
<Button
android:id="#+id/customerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/grey"
android:onClick="toggleClicked"
android:background="#drawable/toggleon"
android:text="Customer"
/>
<Button
android:id="#+id/SupplierButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="toggleClicked"
android:textColor="#color/grey"
android:background="#drawable/toggleoff"
android:text="Supplier"
/>
</LinearLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carrier"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinnerCarrier"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:background="#color/darkgrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/SpinnerTop"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:onClick="showDateTimePickerFrom"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Date"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fromDate"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:background="#color/darkgrey"
android:layout_width="wrap_content"
android:onClick="showDateTimePickeTo"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Date"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/toDate"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group By Profile"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/byprofilecheck"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Related
when I scroll the listview the items changed automatically, in other word an item override other item's view like : when I click on favorite button other items has been changed like this
example:
the item that I clicked
I didn't click on this item
here is my code :
CustomListAdapter.java :
public class CustomListAdapter extends BaseAdapter {
private Context context;
LayoutInflater inflater;
boolean isVoter;
public CustomListAdapter(Context c ) {
this.context = c;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null){
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.date_view,null);
viewHolder = new ViewHolder();
viewHolder.vote = (ImageButton) convertView.findViewById(R.id.vote);
}else {
viewHolder = (ViewHolder)convertView.getTag();
}
isVoter = newsItemArray.get(position).isVoter();
viewHolder.vote.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (!Utility.isNetworkAvailable(context))
Toast.makeText(context, R.string.no_network, Toast.LENGTH_LONG).show();
else
voteBtn( position);
}});
return convertView;
}
public void voteBtn(int position){
if ( !isVoter ) {
viewHolder.vote.setImageResource(R.drawable.button_pressed);
}
else{
viewHolder.vote.setImageResource(R.drawable.button_normal);
}
isVoter = !isVoter;
}
}
private class ViewHolder{
ImageButton vote ;
}
#Override
public int getCount() {
return newsItemArray.size();
}
#Override
public Object getItem(int position) {
return newsItemArray.get(position).getTitle();
}
#Override
public long getItemId(int position) {
return position;
}
}
date_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="wrap_content"
android:orientation="vertical"
android:background="#f2f2f2"
android:gravity="center"
android:elevation="8dp"
android:layout_margin="10dp">
<android.support.v7.widget.CardView
android:id="#+id/newsCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff"
android:layout_margin="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/newsimage1"
android:layout_width="45px"
android:layout_height="45px"
android:src="#mipmap/ic_launcher"
android:scaleType="centerCrop"
/>
<TextView
android:id="#+id/newsname"
android:layout_marginLeft="16dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fox News."
android:textColor="#000000"
android:textSize="20dp"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/time"
android:layout_weight="0.6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2 day ago"
android:textColor="#color/listsub1"
android:textSize="14dp"
android:layout_gravity="center"
/>
<ImageView
android:id="#+id/more"
android:visibility="invisible"
android:layout_width="15dp"
android:layout_height="22dp"
android:src="#drawable/more"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/sourceNews"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp"
>
<TextView
android:id="#+id/news"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Trump’s Plan for AmericanMade iPhonew Wold Be Disastrous. Trump’s Plan for AmericanMade iPhonew Wold Be Disastrous"
android:textSize="20dp"
android:textColor="#color/listtext"
android:lineSpacingExtra="3dp"
/>
<TextView
android:id="#+id/newssub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Why even a President Trump couldn’t make Apple manufacture iPhone in the state."
android:layout_marginTop="5dp"
android:textSize="13dp"
android:textColor="#color/listsub1"
android:lineSpacingExtra="3dp"
/>
<TextView
android:id="#+id/votes_num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:textStyle="bold"
android:textColor="#f40000"
android:maxLines="1"
android:layout_marginTop="5dp"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="#+id/vote"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/star"
android:background="#00ffffff"
android:paddingLeft="5dp" />
<!--
<ImageButton
android:id="#+id/vote"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="#drawable/star"
android:paddingLeft="5dp" />
<Button
android:id="#+id/share"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Share"
android:textColor="#color/background_material_light"/>
<Button
android:id="#+id/comment"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Comment"
android:textColor="#color/background_material_light"/>
-->
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
isVoter and viewHolder should not be global variables within the Adapter. Meaning, you are not actually changing whatever member is returned by newsItemArray.get(position).isVoter()
Try adding the position to the ViewHolder object. Then pass the ViewHolder object into the constructor of the viewHolder.vote.setOnClickListener. Within the OnClickListener you can then call
isVoter = newsItemArray.get(viewHolder.position).isVoter();
newsItemArray.get(viewHolder.position).setVoter(!isVoter);
I am new to android listviews and I am trying to populate a listview in android by a list of items coming from a webservice. I know that the list contains more than one record coming from the webservice but my custom listview displays only the first record from the list. I checked the size of the list and there is always more than one records but the listview is showing only one of them. My custom adapter is like following:
public class ListAdapter extends BaseAdapter {
Context ctx;
LayoutInflater lInflater;
ArrayList<LItem> lstItems;
ListAdapter(Context context, ArrayList<LItem> objects) {
ctx = context;
lstItems = objects;
lInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return lstItems.size();
}
#Override
public Object getItem(int position) {
return lstItems.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.list_style_task
, parent, false);
}
LItem p = getProduct(position);
((TextView) view.findViewById(R.id.tvMaterial )).setText(p.getMName() );
((TextView) view.findViewById(R.id.tvTask )).setText(p.getTName() );
((TextView) view.findViewById(R.id.tvBQuantity )).setText(p.getBQ() );
// CheckBox cbBuy = (CheckBox) view.findViewById(R.id.checkbox);
//cbBuy.setOnCheckedChangeListener(myCheckChangList);
// cbBuy.setTag(position);
// cbBuy.setChecked(p.selected);
return view;
}
LItem getProduct(int position)
{
return ((LItem) getItem(position));
}
ArrayList<LItem> getBox() {
ArrayList<LItem> box = new ArrayList<LItem>();
for (LItem p : lstItems) {
// if (p.selected)
// box.add(p);
}
return box;
}
OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
//getProduct((Integer) buttonView.getTag())= isChecked;
}
};
}
I am binding the listview as:
protected void onPostExecute(List<LItem> li ) {
super.onPostExecute(lstItm);
if(lstItm.size()>0) {
Adp=new ListAdapter(myactivity,lstItm);
lvTasks.setAdapter(Adp);
Log.d("Size---------",Integer.toString(lstItm.size()) );//here it writes more than one as size of the list.
}
}
My xml file for displaying lists is like this:
<?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="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:focusable="false"
android:textColor="#FFF"
android:button="#drawable/custom_checkbox_design"
android:focusableInTouchMode="false"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Task:"
android:id="#+id/textView2"
android:layout_weight="1"
android:textColor="#FFF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="task"
android:id="#+id/tvTask"
android:layout_weight="1"
android:textColor="#FFF"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="20dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Material:"
android:id="#+id/textView1"
android:layout_weight="1"
android:textColor="#FFF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="material"
android:id="#+id/tvMaterial"
android:layout_weight="1"
android:textColor="#FFF"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="45dp"
android:layout_marginRight="20dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balanced Quantity:"
android:id="#+id/textView14"
android:layout_weight="1"
android:textColor="#FFF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bquantity"
android:id="#+id/tvBQuantity"
android:layout_weight="1"
android:textColor="#FFF"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adjust Balanced Quantity:"
android:id="#+id/textView25"
android:layout_weight="1"
android:textColor="#FFF"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/tvAQuantity"
android:layout_weight="1"
android:textColor="#FFF"
/>
</LinearLayout>
</LinearLayout>
My xml for listview is like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="kanix.highrise.com.highrise.generate_material_requisition">
<!-- TODO: Update blank fragment layout -->
<ScrollView android:id="#+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lstTaskQuantity"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="#+id/txtLddsdfabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16dp"
android:text="Req. From :"
android:layout_weight="1"
android:textColor="#fff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:id="#+id/etDate"
android:layout_weight=".5"
android:hint="DD/MM/YYYY"/>
<ImageButton
android:layout_width="35dp"
android:layout_height="35dp"
android:id="#+id/btnimgcal"
android:src="#drawable/calender"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="#+id/txtLddsdfadsbel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16dp"
android:text="For Days :"
android:layout_weight="1"
android:textColor="#fff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="0"
android:id="#+id/editText"
android:layout_weight="1.69" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="#+id/txtLddsddfgfadsbel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16dp"
android:text="Quantity :"
android:layout_weight="1"
android:textColor="#fff" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="0"
android:id="#+id/etQuantity"
android:layout_weight="1.60" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center"
android:orientation="vertical"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#0080FF"
android:background="#fff"
android:text="Generate Requisition"
android:id="#+id/btnSave" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Issue was with the scrollview which was createing the issue. I just removed
<ScrollView android:id="#+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" >
</ScrollView>
and it worked for me :)
I am trying to design a listview wherein i have to display two to three data for rows of each column,but i am not able to do so,i am getting the data has in image a but i want to display has in image b,i can display only single data in each row of each column.For example the column states to display the value of item number and style number ,i am able to display only item number but not style number.
**DataDisplay 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="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView4"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView5"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textSize="25dp"
android:text="TextView" />
</LinearLayout>
**Listview xml**
<LinearLayout 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="0dp"
android:layout_weight="1"
android:divider="#00000000"
android:dividerHeight="5dp"
/>
</LinearLayout>
adapter
public class CustomAdapter extends BaseAdapter{
String [] result;
String [] result1;
String [] result2;
String [] result3;
String [] result4;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(ItemActivity mainActivity, String[] prgmNameList,String[] prgmNameList1,String[] prgmNameList2,String[] prgmNameList3,String[] prgmNameList4) {
// TODO Auto-generated constructor stub
result=prgmNameList;
result1=prgmNameList1;
result2=prgmNameList2;
result3=prgmNameList3;
result4=prgmNameList4;
context=mainActivity;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return result.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;
}
public class Holder
{
TextView tv;
TextView tv1;
TextView tv2;
TextView tv3;
TextView tv4;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.tabitem, null);
holder.tv=(TextView) rowView.findViewById(R.id.textView1);
holder.tv1=(TextView)rowView.findViewById(R.id.textView2);
holder.tv2=(TextView) rowView.findViewById(R.id.textView3);
holder.tv3=(TextView) rowView.findViewById(R.id.textView4);
holder.tv4=(TextView) rowView.findViewById(R.id.textView5);
holder.tv.setText(result[position]);
holder.tv1.setText(result1[position]);
holder.tv2.setText(result2[position]);
holder.tv3.setText(result3[position]);
holder.tv4.setText(result4[position]);
rowView.setBackgroundColor(Color.parseColor("#F1F1FF"));
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
}
});
return rowView;
}
}
called from activity
public static String [] prgmNameList={"123456","456665","123445","5675343"};
public static String [] prgmNameList1={"15.56","15.562","15.67","15.455"};
public static String [] prgmNameList2={"9999","9999","9999","9999"};
public static String [] prgmNameList3={"99%","99%","99%","99%"};
public static String [] prgmNameList4={"9999","9999","9999","9999"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.itemlist);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.item);
context=this;
lv=(ListView) findViewById(R.id.listView);
lv.setAdapter(new CustomAdapter(this, prgmNameList,prgmNameList1,prgmNameList2,prgmNameList3,prgmNameList4));
}
You need to create a custom layout for your row item where you can place two textviews one below the other to show your data as you want. Then override the getView() method of your adapter and inflate this custom layout and populate it with data from an array / list.
See the getView() method in the link mentioned in giacavicchioli's answer.
As user87049 has said this will solve your problem sarah:
**DataDisplay 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="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView4"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:textSize="25dp"
android:text="TextView" />
<TextView
android:id="#+id/textView5"
android:layout_gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:textSize="25dp"
android:text="TextView" />
</LinearLayout>
tell me if this this is not what you want :)
Ah and since I'm a bit busy these days and I may not come to this account on stackoverflow, please send me email to get my attention please [erfan.molaei#gmail.com]
Here is what i did. Make a xml file like this:
<?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="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF" />
</LinearLayout>
</LinearLayout>
This is your custom listview xml file. Now in getView method setText to this all textview as you did for your xml file.
Check out below screen:
I have a problem with my GridView when it receives incomplete row item number, it doesn't scroll anymore. My items are dynamic which are given by the server, I have 3 columns and if the number of GridView items are more than enough to enable scrolling and if the row item is 3, it works fine. For example (9 items):
But if the third row has only 1 or 2 item/s, it doesn't scroll anymore (7 or 8 items):
This has caused me headache more than excitement, my GridView in layout is:
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/white"
android:listSelector="#android:color/transparent"
android:numColumns="3"
android:stretchMode="columnWidth" >
</GridView>
In my activity nothing much, just declaration and setting its adapter. Did I miss anything? I tried adding verticalSpacing and padding separately but nothing's changed.
EDIT:
This is the setup in the whole layout:
Black is a RelativeLayout, FrameLayout and the last ImageView are aligned top and bottom respectively. Top TextView is below FrameLayout, bottom TextView is below top TextView. Now GridView is below bottom TextView and above ImageView, it should expand its height basing to the space left consumed between the first 3 elements and the bottom element. This is how it's setup in my layout.
I believe it's a layout problem more than in my code since I've done dozens of ListView and this has similar implementation.
EDIT2:
The layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SixthActivity" >
<FrameLayout
android:id="#+id/cover_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/cover_image"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#color/gray"
android:scaleType="centerCrop" />
<ProgressBar
android:id="#+id/cover_image_progressbar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="180dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp" />
<TextView
android:id="#+id/school_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/container_sns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:gravity="right"
android:orientation="horizontal" >
<ImageView
android:id="#+id/btn_telephone"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:visibility="gone" />
<ImageView
android:id="#+id/btn_email"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:visibility="gone" />
<ImageView
android:id="#+id/btn_facebook"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:visibility="gone" />
<ImageView
android:id="#+id/btn_twitter"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:visibility="gone" />
<ImageView
android:id="#+id/btn_line"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
<TextView
android:id="#+id/student_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/cover_frame"
android:background="#f8f7f3"
android:padding="10dp"
android:textColor="#color/brown"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/container_news"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/student_name"
android:background="#drawable/bg_news"
android:clickable="true"
android:orientation="horizontal"
android:visibility="gone" >
<TextView
android:id="#+id/news"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="85dp"
android:layout_marginRight="10dp"
android:clickable="true"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/brown"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/container_next_plan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/container_news"
android:background="#drawable/bg_next"
android:clickable="true"
android:orientation="horizontal"
android:visibility="gone" >
<TextView
android:id="#+id/next_plan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="85dp"
android:layout_marginRight="10dp"
android:clickable="true"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/brown"
android:textStyle="bold" />
</RelativeLayout>
<GridView
android:id="#+id/grid_view"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/mypage_footer"
android:layout_below="#id/container_next_plan"
android:background="#ACA899"
android:gravity="center"
android:numColumns="3" >
</GridView>
<ImageView
android:id="#+id/mypage_footer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:scaleType="fitXY" />
</RelativeLayout>
Don't mind the ImageViews, I just took out their source. I needed to retain the setup from my actual layout. The code:
public class SixthActivity extends Activity {
private Integer[] gridViewItem = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sixth);
GridView gridView = (GridView) findViewById(R.id.grid_view);
CustomAdapter adapter = new CustomAdapter(this,
R.layout.item_module, gridViewItem);
gridView.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sixth, menu);
return true;
}
}
The adapter:
public class CustomAdapter extends ArrayAdapter<Integer> {
private Context context;
private int resource;
private Integer[] moduleList;
public CustomAdapter(Context context, int resource,
Integer[] moduleList) {
super(context, resource, moduleList);
// TODO Auto-generated constructor stub
this.context = context;
this.resource = resource;
this.moduleList = moduleList;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(resource, parent, false);
holder = new ViewHolder();
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
holder.tvModuleName = (TextView) row.findViewById(R.id.module_name);
holder.tvModuleImage = (ImageView) row.findViewById(R.id.module_image);
holder.tvModuleName.setText("SAMPLESAMPLE");
return row;
}
public class ViewHolder {
public ImageView tvModuleImage;
public TextView tvModuleName;
}
}
The item layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/item_module"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/module_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/module_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ellipsize="end"
android:singleLine="true" />
</LinearLayout>
Try to add numbers to gridViewItem to add items enough to trigger the scrolling just like in my screenshots, and try taking out 1 or 2 items at the bottom such that that row would be incomplete to replicate my problem. Thanks.
I am working on an app using ListView to show some data which I get from server at Runtime.
I set the data in the list view dynamically. Below is my XML for ROW :
<LinearLayout
android:id="#+id/top_lilay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/top_header_relay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/timeline_header_bg_480" >
<TextView
android:id="#+id/bride_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:text="STELLA"
android:textColor="#android:color/black"
android:textSize="50sp" />
<ImageView
android:id="#+id/and_IV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/bride_tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dip"
android:background="#drawable/and" />
<TextView
android:id="#+id/groom_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/and_IV"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dip"
android:text="JOSE"
android:textColor="#android:color/black"
android:textSize="50sp" />
<TextView
android:id="#+id/time_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/groom_tv"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dip"
android:text="85 DIAS 23 HOURAS 22 MINUS Y 30 SEG"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/text_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time_tv"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dip"
android:layout_marginTop="2dip"
android:text="para nuestro gran dia"
android:textColor="#android:color/white"
android:textSize="15sp" />
</RelativeLayout>
<ImageView
android:id="#+id/bar_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/orange_bar_480" />
<ImageView
android:id="#+id/photo_IV"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:background="#drawable/post_photo" />
</LinearLayout>
<RelativeLayout
android:id="#+id/heading_relay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/top_lilay"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" >
<ImageView
android:id="#+id/profile_pic_IV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:background="#drawable/profile_pic" />
<TextView
android:id="#+id/username_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/profile_pic_IV"
android:text="LOREM IPSUM TITLE"
android:textColor="#android:color/black"
android:textSize="22sp" />
<TextView
android:id="#+id/posttime_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/username_tv"
android:layout_toRightOf="#id/profile_pic_IV"
android:text="Jose Q. a las 2:30 pm el 24 september 2013"
android:textColor="#android:color/black"
android:textSize="12sp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/buttons_relay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/heading_relay"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:weightSum="3" >
<LinearLayout
android:id="#+id/like_lilay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/like_IV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:background="#drawable/like" />
<TextView
android:id="#+id/likes_count_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/likes_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/likes"
android:textColor="#android:color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/comment_lilay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/comment_IV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:background="#drawable/comment" />
<TextView
android:id="#+id/comment_count_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/comment_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/commments"
android:textColor="#android:color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/fav_lilay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/fav_IV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:background="#drawable/favorite" />
<TextView
android:id="#+id/fav_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/favorites"
android:textColor="#android:color/black" />
</LinearLayout>
</LinearLayout>
Just for the 1st ELEMENT I have to show the "top_header_relay" and the rest of the elements I have to change the visibility to GONE. In doing this, the height of the other Rows remains same as the 1st one which result a big Blank Space at the bottom of the Row.
Suggest me how can I resize the height of the other rows of the List at run time.
ADAPTER CLASS:
public class PostsListAdapter extends BaseAdapter implements OnClickListener{
ArrayList<String> itemList=null;
private Activity _mContext=null;
public LayoutInflater inflater=null;
private Context _Context = null;
private ArrayList<ViewHolder> listHolder=null;
private int[] imageList = {R.drawable.calendar_icon,
R.drawable.location_icon,R.drawable.fun_icon,
R.drawable.notification_icon,R.drawable.invitation_icon,
R.drawable.change_wedding,R.drawable.settings_icon,
R.drawable.logout_icon};
/**
* PostsListAdapter
* #param context
* #param itemList
*/
public PostsListAdapter(Activity context,ArrayList<String> itemList) {
super();
this._Context = context;
this._mContext = context;
this.itemList = itemList;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
listHolder = new ArrayList<PostsListAdapter.ViewHolder>();
}
public int getCount() {
return itemList.size();
}
public Object getItem(int position) {
return itemList.get(position);
}
public long getItemId(int position) {
return 0;
}
public static class ViewHolder{
private ImageView _postImageView=null;
private ImageView _profilePicImageView=null;
private TextView _usernameTitleTextView=null;
private TextView _timeTextView=null;
private TextView _likeCountTextView=null;
private TextView _commentsCountTitleTextView=null;
private LinearLayout _likeLinearLayout=null;
private LinearLayout _commentLinearLayout=null;
private LinearLayout _favLinearLayout=null;
private RelativeLayout _topheaderRelay=null;
private ImageView _barViewImageView=null;
}
/**
*
*/
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView==null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.post_list_element, null);
holder._postImageView=(ImageView)convertView.findViewById(R.id.photo_IV);
holder._postImageView.setOnClickListener(this);
holder._profilePicImageView=(ImageView)convertView.findViewById(R.id.profile_pic_IV);
holder._profilePicImageView.setOnClickListener(this);
holder._usernameTitleTextView = (TextView) convertView.findViewById(R.id.username_tv);
holder._usernameTitleTextView.setClickable(false);
holder._timeTextView = (TextView) convertView.findViewById(R.id.posttime_tv);
holder._timeTextView.setClickable(false);
holder._likeCountTextView = (TextView) convertView.findViewById(R.id.likes_count_tv);
holder._likeCountTextView.setClickable(false);
holder._commentsCountTitleTextView = (TextView) convertView.findViewById(R.id.comment_count_tv);
holder._commentsCountTitleTextView.setClickable(false);
holder._likeLinearLayout = (LinearLayout) convertView.findViewById(R.id.like_lilay);
holder._likeLinearLayout.setOnClickListener(this);
holder._commentLinearLayout = (LinearLayout) convertView.findViewById(R.id.comment_lilay);
holder._commentLinearLayout.setOnClickListener(this);
holder._favLinearLayout = (LinearLayout) convertView.findViewById(R.id.fav_lilay);
holder._favLinearLayout.setOnClickListener(this);
convertView.setTag(holder);
}
else
holder=(ViewHolder)convertView.getTag();
if(position!=0){
holder._topheaderRelay = (RelativeLayout) convertView.findViewById(R.id.top_header_relay);
holder._topheaderRelay.setVisibility(View.GONE);
holder._barViewImageView = (ImageView) convertView.findViewById(R.id.bar_view);
holder._barViewImageView.setVisibility(View.GONE);
}else{
holder._topheaderRelay = (RelativeLayout) convertView.findViewById(R.id.top_header_relay);
holder._topheaderRelay.setVisibility(View.VISIBLE);
holder._barViewImageView = (ImageView) convertView.findViewById(R.id.bar_view);
holder._barViewImageView.setVisibility(View.VISIBLE);
}
listHolder.add(holder);
return convertView;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.like_lilay:
break;
case R.id.comment_lilay:
break;
case R.id.fav_lilay:
break;
case R.id.profile_pic_IV:
break;
case R.id.photo_IV:
break;
default:
break;
}
}
}
When you populate the list, getview function is the best place to inflate the view and to set its layout attributes. You can hide the visibility of other rows based on the item position using setvisibility function