I am working on an application in which I am using custom listview and for my listview I have define a row layout for customisation.
In my row layout I have two Relative layouts.
I want to dynamically remove that one Relative layout from my listview and then add it again.
Please help me how can I do that. I have added a screen shot of my layout you can see here
Below is my Row layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/r2_imageslayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_persontext"
android:text="Per Person"
android:textSize="15sp"
android:textColor="#color/toolbar_color"
android:layout_marginLeft="150sp"
android:layout_marginTop="#dimen/size_8"
/>
<TextView
android:layout_width="100sp"
android:layout_height="wrap_content"
android:id="#+id/result2_price"
android:text="$568"
android:textSize="20sp"
android:textStyle="bold"
android:background="#color/yellow"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/size_10"
android:layout_marginTop="#dimen/size_5"
android:paddingLeft="#dimen/size_15"
/>
<ImageView
android:layout_width="30sp"
android:layout_height="20sp"
android:contentDescription="#null"
android:layout_marginLeft="#dimen/size_10"
android:layout_marginTop="#dimen/size_30"
android:id="#+id/r2_departairlineimage"
android:src="#drawable/dl"
/>
<TextView
android:layout_width="40sp"
android:layout_height="20sp"
android:id="#+id/result2_flightcode"
android:text="SG250"
android:textSize="12sp"
android:layout_marginLeft="10sp"
android:layout_below="#+id/r2_departairlineimage"
/>
<ImageView
android:layout_width="30sp"
android:layout_height="20sp"
android:id="#+id/r2_depart_image"
android:layout_toRightOf="#+id/r2_departairlineimage"
android:layout_marginLeft="#dimen/size_15"
android:layout_marginTop="35sp"
android:src="#drawable/depart"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_departtime"
android:text="11:30"
android:textColor="#color/toolbar_color"
android:textSize="#dimen/size_15"
android:layout_toRightOf="#+id/r2_depart_image"
android:layout_marginLeft="#dimen/size_5"
android:layout_marginTop="36sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_dep_citycode"
android:text="Bos"
android:textSize="12sp"
android:layout_toRightOf="#+id/r2_departtime"
android:layout_marginTop="38sp"
android:layout_marginLeft="#dimen/size_3"
/>
<ImageView
android:layout_width="80sp"
android:layout_height="wrap_content"
android:id="#+id/r2_image"
android:contentDescription="#null"
android:src="#drawable/onestop_line"
android:layout_toRightOf="#+id/r2_dep_citycode"
android:layout_toEndOf="#+id/r2_dep_citycode"
android:layout_marginTop="42sp"
android:layout_marginLeft="#dimen/size_10"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_1stoptext"
android:text="1 stop"
android:textSize="12sp"
android:layout_toRightOf="#+id/r2_dep_citycode"
android:layout_toEndOf="#+id/r2_dep_citycode"
android:layout_marginTop="32sp"
android:layout_marginLeft="#dimen/size_30"
/>
<ImageView
android:layout_width="10sp "
android:layout_height="10sp"
android:id="#+id/r2_departclock"
android:layout_toRightOf="#+id/r2_dep_citycode"
android:layout_toEndOf="#+id/r2_dep_citycode"
android:layout_below="#+id/r2_1stoptext"
android:layout_marginTop="5sp"
android:src="#drawable/time_image"
android:layout_marginLeft="#dimen/size_30"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15sp"
android:id="#+id/r2_dep_flightduration"
android:text="5h 60m"
android:textSize="12sp"
android:layout_below="#+id/r2_1stoptext"
android:layout_marginTop="#dimen/size_1"
android:layout_toRightOf="#+id/r2_departclock"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_arrivetime"
android:text="11:30"
android:textColor="#color/toolbar_color"
android:textSize="#dimen/size_15"
android:layout_toRightOf="#+id/r2_image"
android:layout_marginLeft="#dimen/size_5"
android:layout_marginTop="36sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_arrive_citycode"
android:hint="Was"
android:textSize="12sp"
android:layout_toRightOf="#+id/r2_arrivetime"
android:layout_marginTop="38sp"
android:layout_marginLeft="#dimen/size_3"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/result2_returnlayout" >
<ImageView
android:layout_width="30sp"
android:layout_height="20sp"
android:contentDescription="#null"
android:layout_marginLeft="#dimen/size_10"
android:layout_marginTop="#dimen/size_80"
android:id="#+id/r2_return_airlineimage"
android:src="#drawable/dl"
/>
<TextView
android:layout_width="40sp"
android:layout_height="20sp"
android:id="#+id/result2_returnflightcode"
android:text="SG250"
android:textSize="12sp"
android:layout_marginLeft="10sp"
android:layout_below="#+id/r2_return_airlineimage" />
<ImageView
android:layout_width="30sp"
android:layout_height="20sp"
android:id="#+id/r2_return_image"
android:layout_toRightOf="#+id/r2_return_airlineimage"
android:layout_marginLeft="#dimen/size_15"
android:layout_marginTop="80sp"
android:src="#drawable/return_image" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_return_deptime"
android:text="11:30"
android:textColor="#color/toolbar_color"
android:textSize="#dimen/size_15"
android:layout_toRightOf="#+id/r2_return_image"
android:layout_marginLeft="#dimen/size_5"
android:layout_marginTop="80sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_return_depcitycode"
android:text="Bos"
android:textSize="12sp"
android:layout_toRightOf="#+id/r2_return_deptime"
android:layout_marginTop="82sp"
android:layout_marginLeft="#dimen/size_3"/>
<ImageView
android:layout_width="80sp"
android:layout_height="10sp"
android:id="#+id/r2_ret_image"
android:contentDescription="#null"
android:src="#drawable/nonstop"
android:layout_toRightOf="#+id/r2_return_depcitycode"
android:layout_toEndOf="#+id/r2_return_depcitycode"
android:layout_marginTop="85sp"
android:layout_marginLeft="#dimen/size_10"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_return_nonstoptext"
android:text="Non stop"
android:textSize="12sp"
android:layout_toRightOf="#+id/r2_return_depcitycode"
android:layout_toEndOf="#+id/r2_return_depcitycode"
android:layout_marginTop="75sp"
android:layout_marginLeft="#dimen/size_25" />
<ImageView
android:layout_width="10sp "
android:layout_height="10sp"
android:id="#+id/r2_ret_clock"
android:layout_toRightOf="#+id/r2_return_depcitycode"
android:layout_toEndOf="#+id/r2_return_depcitycode"
android:layout_below="#+id/r2_return_nonstoptext"
android:layout_marginTop="5sp"
android:src="#drawable/time_image"
android:layout_marginLeft="#dimen/size_30"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="15sp"
android:id="#+id/r2_ret_flightduration"
android:text="5h 60m"
android:textSize="12sp"
android:layout_marginTop="#dimen/size_1"
android:layout_below="#+id/r2_return_nonstoptext"
android:layout_toRightOf="#+id/r2_ret_clock"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_ret_arrivetime"
android:text="11:30"
android:textColor="#color/toolbar_color"
android:textSize="#dimen/size_15"
android:layout_toRightOf="#+id/r2_ret_image"
android:layout_marginLeft="#dimen/size_5"
android:layout_marginTop="80sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/r2_ret_arrivecitycode"
android:text="Was"
android:textSize="12sp"
android:layout_toRightOf="#+id/r2_ret_arrivetime"
android:layout_marginTop="82sp"
android:layout_marginLeft="#dimen/size_3"/>
</RelativeLayout>
</RelativeLayout>
That's my adapter code:
Result2Adapter(Context context, List list_row)
{
// super(context, resourceID, list_row);
this.context=context;
this.list_row=list_row;
}
#Override
public int getCount() {
return list_row.size();
}
#Override
public Custom_Result getItem(int position) {
return list_row.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
private class ViewHolder
{
ImageView DepAirline_logo, Ret_Airlinelogo;
TextView Dep_Airline_code,dep_time,dep_arr_time,dep_stops,dep_duration,Dep_dep_citycode,Dep_arrivecitycode,Ret_dep_citycode,Ret_arrivecitycode,Ret_Airline_code,Ret_time,Ret_arr_time,
Ret_stops,Ret_duration,price;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder=null;
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if(convertView==null){
convertView=inflater.inflate(R.layout.result2_rowlayout,null);
holder=new ViewHolder();
holder. DepAirline_logo=(ImageView) convertView.findViewById(R.id.r2_departairlineimage);
holder.Dep_Airline_code=(TextView) convertView.findViewById(R.id.result2_flightcode);
holder.dep_time=(TextView) convertView.findViewById(R.id.r2_departtime);
holder.dep_arr_time=(TextView) convertView.findViewById(R.id.r2_arrivetime);
holder.Dep_arrivecitycode=(TextView) convertView.findViewById(R.id.r2_arrive_citycode);
holder.dep_stops=(TextView) convertView.findViewById(R.id.r2_1stoptext);
holder.dep_duration=(TextView) convertView.findViewById(R.id.r2_dep_flightduration);
holder.price=(TextView) convertView.findViewById(R.id.result2_price);
holder.Dep_dep_citycode=(TextView) convertView.findViewById(R.id.r2_dep_citycode);
holder.Ret_Airlinelogo = (ImageView) convertView.findViewById(R.id.r2_return_airlineimage);
holder.Ret_Airline_code = (TextView) convertView.findViewById(R.id.result2_returnflightcode);
holder.Ret_time = (TextView) convertView.findViewById(R.id.r2_return_deptime);
holder.Ret_arr_time = (TextView) convertView.findViewById(R.id.r2_ret_arrivetime);
holder.Ret_arrivecitycode = (TextView) convertView.findViewById(R.id.r2_ret_arrivecitycode);
holder.Ret_dep_citycode = (TextView) convertView.findViewById(R.id.r2_return_depcitycode);
holder.Ret_stops = (TextView) convertView.findViewById(R.id.r2_return_nonstoptext);
holder.Ret_duration = (TextView) convertView.findViewById(R.id.r2_ret_flightduration);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
String retimagename=list_row.get(position).getDep_Airline_code().toLowerCase();
String retpath="drawable/"+retimagename;
int retimageresource=context.getResources().getIdentifier(retpath, null, context.getPackageName());
String imagename=list_row.get(position).getRet_Airline_code().toLowerCase();
String path="drawable/"+imagename;
int imageresource=context.getResources().getIdentifier(path, null, context.getPackageName());
if(imageresource==0)
{
imageresource=R.drawable.flight_icon;
}
if(retimageresource==0)
{
imageresource=R.drawable.flight_icon;
}
Drawable image=context.getResources().getDrawable(imageresource);
Drawable retimage=context.getResources().getDrawable(imageresource);
holder.DepAirline_logo.setImageDrawable(image);
holder.Ret_Airlinelogo.setImageDrawable(retimage);
holder.Dep_Airline_code.setText(list_row.get(position).getDep_Airline_name());
holder.Ret_Airline_code.setText(list_row.get(position).getRet_Airline_name());
holder.dep_time.setText(list_row.get(position).getDepart_time());
holder.Ret_time.setText(list_row.get(position).getRet_dep_time());
holder.dep_arr_time.setText(list_row.get(position).getArrive_time());
holder.Ret_arr_time.setText(list_row.get(position).getRet_arr_time());
holder.dep_stops.setText(list_row.get(position).getDep_stops());
holder.Ret_stops.setText(list_row.get(position).getRet_stops());
holder.dep_duration.setText(list_row.get(position).getDep_duration());
holder.Ret_duration.setText(list_row.get(position).getRet_duration());
holder.Dep_arrivecitycode.setText(list_row.get(position).getDep_CityCode());
holder.Ret_arrivecitycode.setText(list_row.get(position).getArr_citycode());
holder.Ret_dep_citycode.setText(list_row.get(position).getRet_dep_citycode());
holder.Ret_arrivecitycode.setText(list_row.get(position).getRet_arr_citycoode());
holder.price.setText(list_row.get(position).getPrice());
return convertView;
}
You could do that in the adapter class's getView method.
For a particular row by inflating the view and getting the relative layout by using findViewById().
e.g.,
RelativeLayout relativeLayout1 = (RelativeLayout) view.findViewById(R.id.relativeLayoutId);
You can hide the layout by using
relativeLayout1.setVisibility(View.GONE);
and unhide using
relativeLayout1.setVisibility(View.VISIBLE);
Related
I am trying to implement table layout in android.I have table Header and row designed in one xml file and am passing data using adapter.So What is happening is I got scrolling horizontally but with multiple table header repeating on each row.
What I want to achieve is table header should be seen only once and all the rows below it should scroll along with table header.
Here's my xml file
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView android:id="#+id/horizontalView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:scrollbars="horizontal|vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:stretchColumns="*"
android:divider="#color/black"
android:showDividers="middle"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Name"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Type"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Fare"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Tax"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Airline Pnr"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Ticekt Numner"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Cancel"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="18sp"
android:id="#+id/name"/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/type"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/fare"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/tax"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/air_pnr"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/ticket"
android:textColor="#color/black"
android:textSize="18sp" />
<CheckBox
android:id="#+id/check_bx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCEL" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
And here's the image what it looks likescrolling table
UPDATE (2) HERE's Adapter Code
public class Flight_cancel_Adapter extends BaseAdapter {
Context context;
public static ArrayList<Flight_cancel_Details> rowItems;
public static int available_seats;
public static PolicyAdapter adapter;
int TOTAL;
public static ArrayList<String> arraySeat=new ArrayList<String>();
Flight_cancel_Adapter(Context context, ArrayList<Flight_cancel_Details> rowItems) {
this.context = context;
this.rowItems = rowItems;
}
#Override
public int getCount() {
return rowItems.size();
}
#Override
public Object getItem(int position) {
return rowItems.get(position);
}
#Override
public long getItemId(int position)
{
return rowItems.indexOf(getItem(position));
}
/* private view holder class */
private class ViewHolder {
TextView type;
TextView fare;
TextView tax;
TextView air_pnr;
TextView ticket;
TextView namee;
CheckBox box;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.test, null);
holder = new ViewHolder();
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.namee = (TextView) convertView.findViewById(R.id.name);
holder.type = (TextView) convertView.findViewById(R.id.type);
holder.fare = (TextView) convertView.findViewById(R.id.fare);
holder.tax = (TextView) convertView.findViewById(R.id.tax);
holder.air_pnr = (TextView) convertView.findViewById(R.id.air_pnr);
holder.ticket = (TextView) convertView.findViewById(R.id.ticket);
holder.box = (CheckBox) convertView.findViewById(R.id.check_bx);
holder.box.setTag(position);
try
{
final Flight_cancel_Details row_pos = rowItems.get(position);
String name=String.valueOf(row_pos.getName());
String typ=String.valueOf(row_pos.gettypes());
String far=String.valueOf(row_pos.getfares());
String tax=String.valueOf(row_pos.gettax());
String pnr=String.valueOf(row_pos.getair_pnr());
String ticket=String.valueOf(row_pos.getticket());
System.out.print("ROW POS-"+row_pos.getStatus());
if(row_pos.getStatus().equals("CANCELLED"))
{
holder.namee.setText(name);
holder.type.setText(typ);
holder.fare.setText(far);
holder.tax.setText(tax);
holder.air_pnr.setText(pnr);
holder.ticket.setText(ticket);
holder.box.setEnabled(false);
holder.box.setText("CANCELLED");
}else {
holder.namee.setText(name);
holder.type.setText(typ);
holder.fare.setText(far);
holder.tax.setText(tax);
holder.air_pnr.setText(pnr);
holder.ticket.setText(ticket);
holder.box.setEnabled(true);
holder.box.setText("CANCEL");
}
if(row_pos.getTarvel_Status().equals("TRAVELLED"))
{
holder.namee.setText(name);
holder.type.setText(typ);
holder.fare.setText(far);
holder.tax.setText(tax);
holder.air_pnr.setText(pnr);
holder.ticket.setText(ticket);
}
}
catch (Exception e)
{
Log.e("BUS_CANCEL_ADAP ERROR:", e.getMessage());
}
convertView.setTag(holder);
holder.box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
int position = (int) buttonView.getTag();
System.out.println("--CLICKED--" + position);
String contactId = (holder.air_pnr.getText().toString());
System.out.println("--VALUE--" + contactId);
arraySeat.add(contactId);
}
else
{
int position = (int) buttonView.getTag();
System.out.println("--UNCHEKED--" + position);
String contactId = (holder.air_pnr.getText().toString());
System.out.println("--UNCHEKED VALUE--" + contactId);
arraySeat.remove(contactId);
}
}
});
return convertView;
}
}
Use Recyclerview for horizontal scrollview for a better performance
test.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">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Name"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="name"
android:textColor="#color/black"
android:textSize="18sp"
android:id="#+id/name"/>
</LinearLayout>
recyclerview.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView android:id="#+id/horizontalView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:scrollbars="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:listitem="#layout/layout">
</android.support.v7.widget.RecyclerView>
Here my XML file, you should put title for all row TableView (TextView) on LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView android:id="#+id/horizontalView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:scrollbars="horizontal|vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--Title for all row, once for all row -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Name"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Type"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Fare"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Tax"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Airline Pnr"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Ticekt Numner"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Cancel"
android:textAllCaps="false"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold|italic" />
</LinearLayout>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:stretchColumns="*"
android:divider="#color/black"
android:showDividers="middle"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="My Name"
android:textColor="#color/black"
android:textSize="18sp"
android:id="#+id/name"/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/type"
android:text="My Type"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/fare"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/tax"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/air_pnr"
android:textColor="#color/black"
android:textSize="18sp" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/ticket"
android:textColor="#color/black"
android:textSize="18sp" />
<CheckBox
android:id="#+id/check_bx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCEL" />
</TableRow>
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
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 have a problem about TextView in RelativeLayout is not center, (only some objects)
First, I'm use ListAdapter for ListView.
public class ListAdapter extends ArrayAdapter<Menu> {
private LayoutInflater inflater;
public ListAdapter(Context c, ArrayList<Menu> o) {
super(c, 0, o);
inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position, View v, ViewGroup parent) {
View view = null;
if (v == null) {
view = inflater.inflate(R.layout.row, null);
} else {
view = v;
}
final Menu data = this.getItem(position);
TextView title = (TextView) view.findViewById(R.id.title);
ImageView background = (ImageView) view.findViewById(R.id.background);
ImageView icon = (ImageView) view.findViewById(R.id.icon);
TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
subtitle.setText(data.getSubTitle());
title.setText(data.getTitle());
background.setImageDrawable(data.getBackground());
icon.setImageDrawable(data.getIcon());
return view;
}
}
and, My row.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="75dip"
android:layout_height="82dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/background"
android:layout_width="75dip"
android:layout_height="83dip"
android:src="#drawable/mediumorchid" />
<ImageView
android:id="#+id/icon"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_discard" />
</RelativeLayout>
<FrameLayout
android:id="#+id/fl1"
android:layout_width="75dip"
android:layout_height="80dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</FrameLayout>
<RelativeLayout
android:id="#+id/width"
android:layout_width="fill_parent"
android:layout_height="80dip"
android:layout_alignBottom="#+id/fl1"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/fl1"
android:layout_toRightOf="#+id/fl1"
android:background="#ecf0f1" >
<RelativeLayout
android:id="#+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:text="Pure"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="#+id/title"
android:layout_marginTop="5dip"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</RelativeLayout>
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="75dip"
android:layout_height="2dip"
android:layout_alignLeft="#+id/width"
android:layout_alignParentRight="true"
android:layout_below="#+id/width"
android:background="#drawable/cdivider" >
</FrameLayout>
This xml's Graphic Design
But in Device(example grouper) , i discover this problem.
In some object, (example see Help ~) Was centered properly. but, other objects, wasn't centered properly.
and i discover this problem another device(different resolution, size, Android version, density).
What can i do solve this problem??
Try this..
Add android:layout_centerHorizontal="true" for subtitle TextView
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_marginTop="5dip"
android:gravity="center_vertical"
android:layout_centerHorizontal="true"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
or this
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="#+id/title"
android:layout_marginTop="5dip"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
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
i want to change the textview size runtime dynamically which is used in listview but is not take any effect on textview i divide after getting my screen width in 6 part after getting screen width runtime i am assign the textview size from screen width but this textview is in different layout so how to take this layout in my layout and change the size of textview runtime
here i put my layout
Home.xml
<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"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/textlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="12"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/flightlist"
android:text="Destination"
android:textSize="17dp"
android:textStyle="bold" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Flight"
android:textSize="17dp"
android:textStyle="bold" />
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/flightlist"
android:text="Airlines"
android:textSize="17dp"
android:textStyle="bold" />
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Schedule"
android:textSize="17dp"
android:textStyle="bold" />
<TextView
android:id="#+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Term Gate"
android:textSize="17dp"
android:textStyle="bold"
android:background="#drawable/flightlist" />
<TextView
android:id="#+id/text6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Status"
android:textSize="17dp"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="10"
>
</ListView>
</LinearLayout>
list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6"
android:gravity="center">
<TextView
android:id="#+id/textdestination"
android:layout_width="183dp"
android:layout_height="fill_parent"
android:text="Destination"
android:textSize="15dp"
android:gravity="center"
/>
<TextView
android:id="#+id/textflight"
android:layout_width="105dp"
android:layout_height="fill_parent"
android:text="Flight"
android:textSize="15dp"
android:gravity="center"
android:background="#drawable/flightlist"
/>
<TextView
android:id="#+id/textairline"
android:layout_width="185dp"
android:layout_height="fill_parent"
android:text="Airlines"
android:textSize="15dp"
android:gravity="center"/>
<TextView
android:id="#+id/textschedule"
android:layout_width="73dp"
android:layout_height="fill_parent"
android:text="Schedule"
android:textSize="15dp"
android:gravity="center"
android:background="#drawable/flightlist"
/>
<TextView
android:id="#+id/texttermgate"
android:layout_width="105dp"
android:layout_height="fill_parent"
android:text="Term Gate"
android:textSize="15dp"
android:gravity="center"
/>
<TextView
android:id="#+id/textstatus"
android:layout_width="73dp"
android:layout_height="fill_parent"
android:text="Status"
android:textSize="15dp"
android:gravity="center"
android:background="#drawable/flightlist"/>
</LinearLayout>
HomeActivity.java
View inflater=getLayoutInflater().inflate(R.layout.list2, list, false);
TextView textdestination=(TextView)inflater.findViewById(R.id.textdestination);
textdestination.setHeight(50);
textdestination.setWidth((textlayoutwidth*25)/100);
textdestination.setTextSize(100);
You can do that in the getView() method of the Adapter you use for the ListView.
mInflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.list, parent,
false);
holder.tv1 = (TextView) convertView
.findViewById(R.id.textdestination);
holder.tv2 = (TextView) convertView
.findViewById(R.id.textflight);
holder.tv3 = (TextView) convertView
.findViewById(R.id.textairline);
.......
.......
.......
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if(someCondition){
holder.tv1.setLayoutParams(new LinearLayout.LayoutParams(50,50));
holder.tv2setLayoutParams(new LinearLayout.LayoutParams(50,50));
holder.tv3.setLayoutParams(new LinearLayout.LayoutParams(50,50));
.....
.....
.....
}
return convertView;
}
you can change your textview width and height on runtime with :
textdestination.setWidth(pixels);
textdestination.setHeight(pixels);