Android Inside Custom ListView, TextView Weight property not working - android

I have a custom listView. The listview data are setting by some textview horizontally for each rows. In main layout I have same number of textView for setting the title of those columns. My problem is, the main layout working fine with the weight property. But the custom value setting layout for listview which contains the textview is not working with the weight property.
Main Layout : (Weight property working correctly)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:weightSum="8">
<TextView
android:layout_weight="0"
android:id="#+id/cid"
android:layout_width="0dp"
android:textSize="16dp"
android:text="B.Id" />
<TextView
android:layout_weight="1"
android:id="#+id/nm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Name" />
<TextView
android:layout_weight=".9"
android:id="#+id/mob"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Mobile" />
<TextView
android:layout_weight="1.2"
android:id="#+id/eml"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Email" />
<TextView
android:layout_weight=".8"
android:id="#+id/bk_no"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Bike No" />
<TextView
android:layout_weight=".4"
android:id="#+id/dy_rt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Rate" />
<TextView
android:layout_weight=".9"
android:id="#+id/frm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="From Date" />
<TextView
android:layout_weight=".9"
android:id="#+id/to"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="To Date" />
<TextView
android:layout_weight=".25"
android:id="#+id/dy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Dys" />
<TextView
android:layout_weight=".45"
android:id="#+id/cst"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="0"
android:id="#+id/vid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="V.ID" />
<TextView
android:layout_weight=".9"
android:id="#+id/book_dt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="1dp"
android:text="Bk Date" />
<TextView
android:layout_weight=".3"
android:id="#+id/rting"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Rating" />
</LinearLayout>
<ListView
android:id="#+id/list_past_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
</LinearLayout>
Custom ListView Value setting Layout:(report_custom_list)(Weight property not working)
<?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" >
<LinearLayout
android:id="#+id/cus_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:weightSum="8" >
<TextView
android:layout_weight="0"
android:id="#+id/id"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1"
android:id="#+id/nm"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".9"
android:id="#+id/mob"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="1.2"
android:id="#+id/eml"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".8"
android:id="#+id/bk_no"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".4"
android:id="#+id/dy_rt"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".9"
android:id="#+id/frm"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".9"
android:id="#+id/to"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".25"
android:id="#+id/dy"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".45"
android:id="#+id/cst"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="0"
android:id="#+id/vid"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".9"
android:id="#+id/book_dt"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:layout_weight=".3"
android:id="#+id/rting"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Custom Adapter Setting values:
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Object[] id_obj=_id.toArray();
Object[] name_obj=c_name1.toArray();
Object[] mb_obj=m_no1.toArray();
Object[] eml_obj=email1.toArray();
...
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.report_custom_list, null);
if(position%2==0)
rowView.setBackgroundColor(Color.YELLOW);
else
rowView.setBackgroundColor(Color.GRAY);
holder.tv=(TextView) rowView.findViewById(R.id.id);
holder.tv1=(TextView) rowView.findViewById(R.id.nm);
holder.tv2=(TextView) rowView.findViewById(R.id.mob);
...
holder.tv.setText((CharSequence) id_obj[position]);
holder.tv1.setText((CharSequence) name_obj[position]);
holder.tv2.setText((CharSequence) mb_obj[position]);
...
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
return rowView;
}
Before I hard coded the width for the textview. But if it goes to different screen the design collapse. How to fix this?

Probably the problem is:
​​
<ListView
android:id="#+id/list_past_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>`
Replace layout_width="wrap_content" with layout_width="match_parent"

change listviews layout_width to fill_parent
android:layout_width="fill_parent"

I think you have to update you main layout file with this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/list_past_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ListView> </LinearLayout>
and make some changes in Adapter class also
public View getView(final int position, View convertView, ViewGroup parent) {
final Object[] id_obj=_id.toArray();
Object[] name_obj=c_name1.toArray();
Object[] mb_obj=m_no1.toArray();
Object[] eml_obj=email1.toArray();
...
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.report_custom_list, null);
if(position%2==0)
rowView.setBackgroundColor(Color.YELLOW);
else
rowView.setBackgroundColor(Color.GRAY);
holder.tv=(TextView) rowView.findViewById(R.id.id);
holder.tv1=(TextView) rowView.findViewById(R.id.nm);
holder.tv2=(TextView) rowView.findViewById(R.id.mob);
...
if(position == 0){
holder.tv.setText("Title1");
holder.tv.setText("Title2");
holder.tv.setText("Title3");
....
}
else{
holder.tv.setText((CharSequence) id_obj[position]);
holder.tv1.setText((CharSequence) name_obj[position]);
holder.tv2.setText((CharSequence) mb_obj[position]);
...
}
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
return rowView;}

Related

Listview displays only one row from the list

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 :)

How to remove list view item in list view android?

In my application i have one custom list view. whenever i click the close image list item, the list item layout must be removed with space. i used visibility:gone attribute, the list item layout deleted but the space is visible. I am using listview in scroll view ,,that was also not working....please help me out.
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.recharge_listitem, null);
TextView accountnumber = (TextView) convertView
.findViewById(R.id.accountnumber);
TextView servicename = (TextView) convertView
.findViewById(R.id.servicetypname);
TextView planamount = (TextView) convertView
.findViewById(R.id.rechargeamount);
final ImageView close = (ImageView) convertView
.findViewById(R.id.crosse_close_img);
final LinearLayout layoutrecharge=(LinearLayout)convertView.findViewById(R.id.rechargelay);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
layoutrecharge.setVisibility(View.GONE);
}
});
accountnumber.setText("Rs."+bpData.get(position).getAccountNumber());
servicename.setText(bpData.get(position).getServicename());
planamount.setText(bpData.get(position).getRechargeamount());
return convertView;
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e365a">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:text="PAYMENT"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:text="Your Recharges"
android:textColor="#1e365a"
android:textSize="20dp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#drawable/dottedline_view" />
<ListView
android:id="#+id/recharge_lv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</ListView>
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginTop="12dp"
android:background="#1e365a" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Amount to be Paid"
android:textColor="#1e365a"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Rs.130"
android:textColor="#1e365a"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="#+id/ev_b_dob"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="50"
android:hint="Enter coupn code"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bt_apply"
style="#style/payment_button_style"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="-5dp"
android:layout_weight="20"
android:gravity="center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp">
<CheckBox
android:id="#+id/cb_reload_cash"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pay using Reload Cash"
android:textColor="#1e365a"
android:textSize="20dp"
android:layout_marginLeft="12dp"/>
</LinearLayout>
<Button
android:id="#+id/atmdebit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="ATM/DEBIT/CREDIT"
android:textColor="#ffffff"
android:textSize="20dp"/>
<Button
android:id="#+id/netbankng_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="NET BANKING"
android:textColor="#ffffff"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
please help me.
custom listview item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rechargelay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/accountnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8008505106" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="(" />
<TextView
android:id="#+id/servicetypname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vodafone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=")" />
</LinearLayout>
<TextView
android:id="#+id/rechargeamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RS.30"
android:layout_weight="1" />
<ImageView
android:id="#+id/crosse_close_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/close"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Set View.GONE for View is not right way to remove row from ListView. to remove row remove select row item from Adapter data-source and call notify data change method of adapter to populate changes:
close.setTag(position);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int deletePos=Integer.parseInt(v.getTag().toString());
bpData.remove(deletePos);
notifyDataSetChanged();
}
});
Set visibility View.GONE of SCROLL VIEW or other parent of list view....

Error in Android 2.x with the infowindow background

This is my problem in all info window I have are too big, and I like to set up at 180dpheight and 300dp width, or warp_content instead:
I realized that the problem only occurs in version 2.2 and Android 2.3, on Android 4.1 dont have problems, and I do not try on version 3.x
Any idea how to fix it?
I read other post that said changed the getInfoContent for getInfoWindow, but I already have that way.
InfoWindow.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#243439"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imagen"
android:layout_width="114dp"
android:layout_weight="0.5"
android:layout_height="174dp"
android:contentDescription="#string/app_name"/>
<LinearLayout
android:layout_width="174dp"
android:layout_height="174dp"
android:orientation="vertical" >
<TextView
android:id="#+id/titulo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textColor="#FFFFFF"
android:gravity="center_horizontal|center"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/direccion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:textColor="#FFFFFF"
android:gravity="center_horizontal|center"
android:textSize="12sp" />
<TextView
android:id="#+id/vermas"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:textColor="#FFFFFF"
android:gravity="bottom|center_horizontal"
android:text="#string/vermas"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
The fragment.java:
googlemap.setInfoWindowAdapter(new InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker marker) {
View v = getLayoutInflater(null).inflate(R.layout.infowindow, null);
TextView titulo = (TextView) v.findViewById(R.id.titulo);
TextView direccion = (TextView) v.findViewById(R.id.direccion);
ImageView imagen = ((ImageView)v.findViewById(R.id.imagen));
titulo.setText(marker.getTitle());
direccion.setText(marker.getSnippet());
if(hash.get(marker) != null)
imagen.setImageDrawable(getResources().getDrawable(hash.get(marker)));
return v;
}
//..
#Override
public View getInfoContents(Marker marker) {
// TODO Auto-generated method stub
return null;
}
});
}
try below coxmk
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#243439"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imagen"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="0.5"
android:contentDescription="#string/app_name" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/titulo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center_horizontal|center"
android:textColor="#FFFFFF"
android:textSize="17sp"
android:textStyle="bold" />
<TextView
android:id="#+id/direccion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:gravity="center_horizontal|center"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<TextView
android:id="#+id/vermas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center_horizontal"
android:text="test"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>

left and right alignment rows inside Listview?

My goal is below image
And i have below codes
row_right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/me"
android:layout_gravity="right"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggghyjkljgfdgjlkhfdhklggg" />
</LinearLayout>
</LinearLayout>
row_left.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:background="#drawable/you"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggggg" />
</LinearLayout>
</LinearLayout>
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="0px"
android:layout_weight="1"
android:scrollbars="vertical"
android:divider="#null"
android:dividerHeight="0dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/content"
android:layout_width="253dp"
android:layout_height="wrap_content"
android:autoText="false"
android:capitalize="none"
android:ems="10"
android:scrollHorizontally="true"
android:singleLine="true"
android:textSize="16sp"
android:hint="Enter text"
>
</EditText>
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
</LinearLayout>
but my result become
How i can Fix it?
UPDATE1
my listAdapter.java
public class ListAdapter1 extends BaseAdapter {
private LayoutInflater myInflater;
private List<SmsInformation> list;
public ListAdapter1(Context context) {
myInflater = LayoutInflater.from(context);
}
public void setData(List<SmsInformation> list2) {
this.list = list2;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
if (list.get(position).getTypeOfSms().equals("send"))
convertView = myInflater.inflate(R.layout.raw_left, null);
else
convertView = myInflater.inflate(R.layout.raw_right, null);
holder = new ViewHolder();
holder.message = (TextView) convertView.findViewById(R.id.message);
holder.dateAndTime = (TextView) convertView.findViewById(R.id.dataAndTime);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.message.setText(list.get(position).getMessageContent());
holder.dateAndTime.setText(list.get(position).geTime()+list.get(position).getDate());
return convertView;
}
static class ViewHolder {
TextView message;
TextView dateAndTime;
}
}
Changes made:
~ in row_right.xml & row_left.xml, layout_width attribute of the parent LinearLayout should be set to wrap_content instead of match_parent
~ in main.xml, layout_width attribute of ListView should be set to match_parent. not wrap_content
Try the following code:
~ row_right.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/me"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggghyjkljgfdgjlkhfdhklggg" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
~ row_left.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" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/you"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggggg" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
~ main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:scrollbars="vertical"
android:divider="#null"
android:dividerHeight="0dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/content"
android:layout_width="253dp"
android:layout_height="wrap_content"
android:autoText="false"
android:capitalize="none"
android:ems="10"
android:scrollHorizontally="true"
android:singleLine="true"
android:textSize="16sp"
android:hint="Enter text"
>
</EditText>
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
</LinearLayout>
Just a guess. in main.xml change width of your ListView to match_parent.
Also add appropriate weight to the layout containing EditText and button. Now the whole space will be assigned to the listView.

Change The Textview Size Runtime in listview

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);

Categories

Resources