Memory issue with items in BaseAdapter - android

I have a ListView where every row view is inflated from this xml layout (by activity layout inflater):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/topic_list_item_selector"
android:orientation="horizontal"
android:paddingLeft="#dimen/list_item_padding_horizontal_big"
android:paddingBottom="#dimen/list_item_padding_vertical_big"
android:paddingTop="#dimen/list_item_padding_vertical_big" >
<LinearLayout
android:id="#+id/topics_list_edit_row_label_color"
android:layout_width="#dimen/label_rect_edge_size"
android:layout_height="#dimen/label_rect_edge_size"
android:orientation="vertical" >
<TextView
android:id="#+id/topics_list_edit_row_label_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ffffff"
android:textSize="#dimen/label_text_size" />
</LinearLayout>
<LinearLayout
android:id="#+id/topics_list_edit_row_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/topics_list_edit_row_text_title"
style="#style/DefaultText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="title" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/topics_list_edit_row_text_detail_section"
style="#style/DetailText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2 sections"
android:textColor="#818181" />
<TextView
android:id="#+id/topics_list_edit_row_text_detail_point"
style="#style/DetailText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="85 points"
android:textColor="#818181" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
When I return this view in my Adapter via getView(), everything works normally.
But when I change some text in TextView via setText() in getView(), my app consumes about 1mb more with every screen rotation:
public class TopicListAdapter extends BaseAdapter{
...
public View getView(int position, View convertView, ViewGroup parent) {
View rowView;
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.topics_list_edit_row, parent, false);
...
Typeface myTypeface = Typeface.createFromAsset(context.getAssets(), "Roboto-Thin.ttf"); //Added
TextView labelT = (TextView) rowView.findViewById(R.id.topics_list_edit_row_label_text);
labelT.setTypeface(myTypeface); //Added
labelT.setText("A"); //!!!! when I delete this line everything works normally !!!!
...
}
...
}
}
I think maybe my activity context remains alive after every screen rotation but if this is the case then how does it happen and how do I avoid it?

Related

Custom ListView Items are not clickable

I am working on an application which contains Custom ListView on its main activity. It was working fine but the day before yesterday, list view items are suddenly become non-clickable. I've searched a lot, but no answer solved my this issue. It is strange. Normal list view is working good, but custom isn't. What may be the problem?
Edit: Custom List View is as normal as it is, nothing odd. I am giving here CustomAdapter class.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null){
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.custom_list, null);
}
ClassDetailPedia detailPedia = personDetail.get(position);
if(detailPedia !=null){
TextView txtPersonName = (TextView) convertView.findViewById(R.id.txtPersonName);
TextView txtReason = (TextView) convertView.findViewById(R.id.txtReason);
TextView txtTags = (TextView) convertView.findViewById(R.id.txtTags);
TextView txtDate = (TextView) convertView.findViewById(R.id.txtDate);
ImageView imgPerson = (ImageView) convertView.findViewById(R.id.imgPerson);
txtPersonName.setText(detailPedia.getTitle());
txtReason.setText("Description: " + detailPedia.getDescription());
txtTags.setText("Tags: " + detailPedia.getTags());
txtDate.setText(GetFormattedDate(detailPedia.getDated()));
if(detailPedia.getImage() != null) {
imgPerson.setImageURI(detailPedia.getImage());
imgPerson.setScaleType(ImageView.ScaleType.CENTER);
}
}
return convertView;
}
and it extends ArrayAdapter<ClassDetailPedia>
And here I am setting CustomAdapter
ListView lstPersons = (ListView) findViewById(R.id.lstDetail);
lstPersons.setAdapter(new CustomAdapter(getApplicationContext(), R.layout.custom_list, pediaList));
custom_list.xml
<?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="wrap_content"
android:background="#drawable/shape_list"
android:gravity="center">
<ImageButton
android:layout_width="80dp"
android:layout_height="60dp"
android:src="#drawable/empty_picture"
android:id="#+id/imgPerson"
android:scaleType="centerCrop" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="2dp">
<TextView
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friday, April 1, 2016 # 8:30pm"
android:id="#+id/txtDate"
android:textStyle="italic"
android:textSize="12sp"
android:layout_below="#+id/txtTags"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="3dp"
android:layout_marginRight="3dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Mr. Bill Gates"
android:id="#+id/txtPersonName"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="3dp"
android:singleLine="true"
android:textSize="17sp"
android:layout_marginBottom="3dp"
android:textStyle="bold"/>
<TextView
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reason: Marketing Strategy"
android:id="#+id/txtReason"
android:layout_below="#+id/txtPersonName"
android:layout_alignParentStart="true"
android:layout_marginStart="3dp"
android:singleLine="true"
android:layout_marginTop="-3dp"
android:textSize="13sp"/>
<TextView
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags: business, start-up"
android:id="#+id/txtTags"
android:layout_below="#+id/txtReason"
android:layout_alignParentStart="true"
android:layout_marginStart="3dp"
android:singleLine="true"
android:textSize="13sp"/>
</RelativeLayout>
</LinearLayout>
Try add android:descendantFocusability="blocksDescendants" for the root view of your custom list item (in your case it is LinearLayout)
<?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="wrap_content"
android:background="#drawable/shape_list"
android:gravity="center"
android:descendantFocusability="blocksDescendants"
>
...
</LinearLayout>
I made new Application, copied and pasted all the files and code and it's working fine. I don't know what caused the problem and why it is working perfectly know.

Aligning ListView text element with TableLayout element

I have a TableLayout with two TextView elements representing the headings of a table, beneath the TableLayout I have a ListView each ListView item has a checkbox followed by two TextView elements representing the value for that column. So something like this
The problem is the right hand column isn't aligned with the TableRow second cell. Instead it appears just to the right of the end of the first ListView item text element. How can I acheive this?
Here's what I have
main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parentPanel"
tools:context=".MainActivity">
<TableLayout
android:id="#+id/surveys_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<TableRow android:layout_height="wrap_content">
<TextView
android:id="#+id/survey_name_header"
android:layout_weight="1"
android:background="#drawable/header_cell_shape"
android:text="#string/survey_name"
android:textColor="#color/white" />
<TextView
android:id="#+id/survey_class_header"
android:layout_weight="1"
android:background="#drawable/header_cell_shape"
android:text="#string/survey_class"
android:textColor="#color/white" />
</TableRow>
</TableLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/surveys_table" />
</RelativeLayout>
survey_list_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:layout_marginTop="7dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="7dp"
android:layout_toRightOf="#+id/textView1" />
</RelativeLayout>
I would assume I need to modify the layout parameters in the addView() method of my ListAdapter but I'm not sure how?
#Override
public View getView(int position, View convertView, final ViewGroup parent) {
View view = null;
if (convertView == null) {
view = inflater.inflate(R.layout.survey_list_item, parent, false);
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox1);
TextView surveyName = (TextView) view.findViewById(R.id.textView1);
TextView surveyClass = (TextView) view.findViewById(R.id.textView2);
//What to do here?
} else {
view = convertView;
}
return view;
}

Button inside ListView not clickable

I want to be able to click on a button inside an item of a ListView. It should have a different effect from clicking the whole item. I realize there are several questions asked on stackoverflow, but none of the suggestions works for me.
The ListView is inside a Fragment.
Layout of the fragment:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".EventFragment" >
<ListView
android:id="#+id/event_list"
android:background="#C0FFFFFF"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp" />
</RelativeLayout>
Layout of each list item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#C0101010">
<TextView
android:id="#+id/event_list_separator"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="separator"
android:textColor="#android:color/white" />
<LinearLayout
android:id="#+id/event_list_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFFFF"
android:padding="6dip" >
<ImageView
android:id="#+id/event_list_element_icon"
android:layout_width="26dip"
android:layout_height="60dip"
android:layout_marginRight="6dip"
android:contentDescription="TODO" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/event_list_element_firstLine"
android:layout_width="match_parent"
android:layout_height="25dip"
android:text="item_header"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dip"
android:orientation="horizontal" >
<TextView
android:id="#+id/event_list_element_secondLine"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Description"
android:textSize="14sp" />
<Button
android:id="#+id/event_list_element_button_1"
android:layout_width="132dip"
android:layout_height="match_parent"
android:drawableLeft="#drawable/ic_button1"
android:text="Participate"
android:textStyle="bold"
android:textSize="14sp"
/>
<Button
android:id="#+id/event_list_element_button_2"
android:layout_width="110dip"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:drawableLeft="#drawable/ic_button2"
android:singleLine="true"
android:text="No thanks"
android:textStyle="bold"
android:gravity="center_vertical"
android:textSize="14sp"
/>
<TextView
android:id="#+id/event_list_element_additional_text"
android:layout_width="100dip"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:singleLine="true"
android:gravity="center_vertical"
android:text="sample"
android:textStyle="bold"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
My list adapter is:
public class EventAdapter extends ArrayAdapter<Event> {
static class ViewHolder {
TextView separator;
LinearLayout relativeLayout;
TextView eventHeader;
TextView eventDescription;
ImageView blueDot;
Button button1;
Button button2;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater)
_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.event_list_item, parent, false);
viewHolder = new ViewHolder();
viewHolder.relativeLayout = (LinearLayout) convertView.findViewById(R.id.event_list_element);
viewHolder.blueDot = (ImageView) convertView.findViewById(R.id.event_list_element_icon);
viewHolder.eventHeader = (TextView) convertView.findViewById(R.id.event_list_element_firstLine);
viewHolder.eventDescription = (TextView) convertView.findViewById(R.id.event_list_element_secondLine);
viewHolder.button1 = (Button) convertView.findViewById(R.id.event_list_element_button1);
viewHolder.button2 = (Button) convertView.findViewById(R.id.event_list_element_button2);
viewHolder.separator = (TextView) convertView.findViewById(R.id.event_list_separator);
convertView.setTag(viewHolder);
} else{
viewHolder = (ViewHolder) convertView.getTag();
}
final Event item = getItem(position);
if (item != null) {
OnClickListener listener = new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(_context, "boo!", Toast.LENGTH_SHORT).show();
}
};
viewHolder.button1.setOnClickListener(listener);
}
return convertView;
}
}
The problem is that the two buttons are not clickable. What I tried to far:
ListView listView = (ListView) rootView.findViewById(R.id.event_list);
listView.setItemsCanFocus(true);
I also tried setting on the button:
android:focusable="true"
android:clickable="true"
I also experimented with android:descendantFocusability.
None of my tries made the buttons clickable.
Insert the attribute android:descendantFocusability="blocksDescendants" in the Parent Layout declaration of each list item.
The xml should be as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:background="#C0101010">
<TextView
android:id="#+id/event_list_separator"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="separator"
android:textColor="#android:color/white" />
<LinearLayout
android:id="#+id/event_list_element"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFFFF"
android:padding="6dip" >
<ImageView
android:id="#+id/event_list_element_icon"
android:layout_width="26dip"
android:layout_height="60dip"
android:layout_marginRight="6dip"
android:contentDescription="TODO" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/event_list_element_firstLine"
android:layout_width="match_parent"
android:layout_height="25dip"
android:text="item_header"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dip"
android:orientation="horizontal" >
<TextView
android:id="#+id/event_list_element_secondLine"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Description"
android:textSize="14sp" />
<Button
android:id="#+id/event_list_element_button_1"
android:layout_width="132dip"
android:layout_height="match_parent"
android:drawableLeft="#drawable/ic_button1"
android:text="Participate"
android:textStyle="bold"
android:textSize="14sp"
/>
<Button
android:id="#+id/event_list_element_button_2"
android:layout_width="110dip"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:drawableLeft="#drawable/ic_button2"
android:singleLine="true"
android:text="No thanks"
android:textStyle="bold"
android:gravity="center_vertical"
android:textSize="14sp"
/>
<TextView
android:id="#+id/event_list_element_additional_text"
android:layout_width="100dip"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:singleLine="true"
android:gravity="center_vertical"
android:text="sample"
android:textStyle="bold"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I found the solution! I wanted to update the list of events periodically (right now it's a thread running every x milliseconds, later I want to switch that to only update the event list when there is a change). Anyway, the code was (inside my main activity):
private BroadcastReceiver _bReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(RECEIVE_EVENT)) {
Bundle bundle = intent.getExtras();
Event event = (Event) bundle.get("event");
showEvent(event);
}
}
};
private void showEvent(final Event event){
final Context context = this;
runOnUiThread(new Runnable() {
public void run() {
final ListView listview = (ListView) findViewById(R.id.event_list);
EventAdapter adapter = new EventAdapter(context, id.event_list, getEventList());
listview.setAdapter(adapter);
}
});
}
Setting the adapter each time is certainly not the right approach. Once I changed that to only set the adapter once, it worked like suggested using android:descendantFocusability="blocksDescendants"

Views in list are not at the corrects size

I have a list view and an adapter. My problem is that the rows in the list are always "wrap content" even though I specifically stated the height as "150dp".
This is my adapter:
private class LiveEventsAdapter extends BaseAdapter {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View contentView = convertView;
if (contentView == null) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
contentView = inflater.inflate(R.layout.live_match_row, null);
TypefaceManager.getInstance(LiveMatchActivity.this).assignTypeface(contentView);
}
if (events != null) {
Event event = events.getEventsList().get(position);
TypefaceManager typefaceManager = TypefaceManager.getInstance(LiveMatchActivity.this);
TextView eventText;
TextView minute;
ImageView eventIcon;
minute = (TextView) contentView.findViewById(R.id.live_match_minute);
if (event.getOrientation().equals("home")) {
eventText = (TextView) contentView.findViewById(R.id.home_team_event_text);
eventIcon = (ImageView) contentView.findViewById(R.id.home_team_event_img);
} else {
eventText = (TextView) contentView.findViewById(R.id.away_team_event_text);
eventIcon = (ImageView) contentView.findViewById(R.id.away_team_event_img);
}
minute.setText(event.getMinute() + "\'");
eventText.setText(event.getDescription());
minute.setTypeface(typefaceManager.getTypeface("bold"));
eventText.setTypeface(typefaceManager.getTypeface("bold"));
}
}
That's how I "setadapter":
ListView eventsListView = (ListView) findViewById(R.id.live_match_list);
eventsListView.setAdapter(new LiveEventsAdapter());
and that's my rows layout:
<?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="150dp"
android:background="#drawable/background_button" >
<TextView
android:id="#+id/live_match_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="82&apos;" />
<TextView
android:id="#+id/home_team_event_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="false"
android:layout_alignRight="#+id/home_team_event_img"
android:layout_centerVertical="true"
android:paddingLeft="4dp"
android:paddingRight="4dp" />
<ImageView
android:id="#+id/home_team_event_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginRight="4dp"
android:layout_toLeftOf="#+id/live_match_minute" />
<ImageView
android:id="#+id/away_team_event_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_centerVertical="true"
android:layout_marginLeft="4dp"
android:layout_toRightOf="#+id/live_match_minute" />
<TextView
android:id="#+id/away_team_event_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/away_team_event_img"
android:paddingLeft="4dp"
android:paddingRight="4dp" />
Why is it that the rows in my list are always set on the same size, no matter what I put in?
This will NOT work.
This is what you should do.
<?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="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/background_button" >
<TextView
android:id="#+id/live_match_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="82&apos;" />
</RelativeLayout>
</RelativeLayout>
Basically, add another layout and specify the height to that layout.
When working with adapter views specifying a height for the root layout doesn't work.

Listview with Textview and 2 Edittext in a single row in android

I want to have a single "Textview" and 2 "Edittext" in a single row.I have tried the following code:
Xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<TextView
android:id="#+id/vegtext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<EditText
android:id="#+id/vegquantity"
android:hint="Qty"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="1"
/>
<EditText
android:id="#+id/vegprice"
android:layout_width="100dp"
android:layout_height="100dp"
android:hint="price"
android:layout_weight="1"
/>
</LinearLayout>
Getview in adapter:
#Override
public View getView(int position, View convertview, ViewGroup parent)
{
VeglistHolder holder;
// TODO Auto-generated method stub
if(convertview == null)
{
LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertview = inflater.inflate(R.layout.veglistrow, null);
holder = new VeglistHolder();
holder.text = (TextView) convertview
.findViewById(R.id.vegtext);
holder.Qtyedit = (EditText) convertview
.findViewById(R.id.vegquantity);
holder.priceedit = (EditText) convertview
.findViewById(R.id.vegprice);
convertview.setTag(holder);
}
else
{
holder = (VeglistHolder) convertview.getTag();
}
holder.text.setText(vegitems[position]);
return convertview;
}
But the Edittext is not there in the row. Also some blank space is coming below the "TExtview" .I searched for "Lots of" post regarding this but i cant solve this.Please help me to solve this..Thanks in advance.
Try to use weightSum in main layout for equal partition as below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="3"
android:orientation="vertical" >
Use a Realative layout. Modify the attributes to suit your requirement
<?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"
>
<TextView
android:id="#+id/textView1"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="58dp"
android:text="TextView" />
<EditText
android:id="#+id/editText1"
android:layout_width="60dp" //set to whatever you desire
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/textView1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="60dp"// //set to whatever you desire
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText1"
android:layout_alignBottom="#+id/editText1"
android:layout_alignParentRight="true"
android:layout_marginRight="70dp"
android:ems="10"
android:inputType="textPersonName" />
</RelativeLayout>
Well your problem is that you set the width and the height of the TextView to fill parent

Categories

Resources