I have just created my first custom adapter, which works great.
And with that, I created a rowlayout.xml for the adapter to fill.
But I have one issue, the row is not dynamic, so if I try to put a text that is longer than the row in, the row wont expand, but instead cut the text off. (see pic. here: http://tinyurl.com/paxdt3a)
Here is my rowLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<!--The second line is used for the date of the post-->
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Time and date"
android:textSize="12sp" />
<!--The first line is used to the post-->
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="Post"
android:textSize="16sp" />
</RelativeLayout>
And here is my Adapter:
public class MyAdapter extends ArrayAdapter<UserPost> {
private final Context context;
private final List<UserPost> posts;
public MyAdapter(Context context, List<UserPost> posts) {
super(context, R.layout.rowlayout, posts);
this.context = context;
this.posts = posts;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
TextView firstText = (TextView) rowView.findViewById(R.id.firstLine);
TextView secondText = (TextView) rowView.findViewById(R.id.secondLine);
//Insert the post
firstText.setText(posts.get(position).getMessage());
//Insert the time
secondText.setText(posts.get(position).getDate());
return rowView;
}
}
Does anyone have any idea on how to solve this?
Thanks!
UPDATE (SOLUTION):
Okay, so I made some changes in my rowlayout.xml, and I finally came up with this, which works!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip" >
<!--The first line is used to the post-->
<TextView
android:id="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="Post"
android:textSize="16sp" />
<!--The second line is used for the date of the post-->
<TextView
android:id="#+id/secondLine"
android:layout_below="#+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ellipsize="marquee"
android:singleLine="false"
android:text="Time and date"
android:textSize="12sp" />
</RelativeLayout>
On your item layoutyou have android:layout_height="?android:attr/listPreferredItemHeight" meaning you are forcing a specific row height for all rows change to android:layout_height="wrap_content"
what simply you can do is to remove the singleLine property
android:singleLine="false"
or you can do like this
public class MyAdapter extends ArrayAdapter<UserPost> {
private final Context context;
private final List<UserPost> posts;
public MyAdapter(Context context, List<UserPost> posts) {
super(context, R.layout.rowlayout, posts);
this.context = context;
this.posts = posts;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(text.length>MAX_LENGTH){
View rowView = inflater.inflate(R.layout.rowlayout1, parent, false);
//....
}else{
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
TextView firstText = (TextView) rowView.findViewById(R.id.firstLine);
TextView secondText = (TextView) rowView.findViewById(R.id.secondLine);
//Insert the post
firstText.setText(posts.get(position).getMessage());
//Insert the time
secondText.setText(posts.get(position).getDate());
}
return rowView;
}
}
Related
Hello dear Stackoverflow community. I'm coming to you for help, as you can guess.
I have a ListView for which each row should follow this layout, row_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="#color/brownish">
<ImageView
android:id="#+id/passport_flag"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="6dp"
android:contentDescription="#string/country_flag" />
<TextView
android:id="#+id/exp_date"
android:layout_width="wrap_content"
android:layout_height="16dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/exp_date"
android:textSize="12sp"
android:textColor="#color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginStart="6dp" />
<TextView
android:id="#+id/birth_date"
android:layout_width="wrap_content"
android:layout_height="16dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/birth_date"
android:textSize="12sp"
android:textColor="#color/white"
android:layout_above="#+id/exp_date"
android:layout_alignStart="#+id/exp_date" />
<TextView
android:id="#+id/document_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_alignStart="#+id/exp_date"
android:layout_above="#id/birth_date"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:text="#string/document_number"
android:textSize="16sp"
android:textColor="#color/white" />
</RelativeLayout>
I implemented a custom ArrayAdapter, for which here is the code:
public class CustomArrayAdapter extends ArrayAdapter<EPassport> {
public static final String TAG = "CustomArrayAdapter";
private final String DOCUMENT_NUMBER = "Passport number: ";
private final String DATE_OF_BIRTH = "Date of birth: ";
private final String DATE_OF_EXPIRY = "Date of expiry: ";
private Context context;
private List<EPassport> ePassportsList;
private static class ViewHolder {
public TextView documentNumber;
public TextView birthDate;
public TextView expDate;
public ImageView flag;
}
public CustomArrayAdapter(Context context, List<EPassport> ePassportsList) {
super(context, R.layout.row_layout, ePassportsList);
this.context = context;
this.ePassportsList = ePassportsList;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater =
(LayoutInflater) context
.getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.row_layout, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.documentNumber = (TextView) rowView.findViewById(R.id.document_number);
viewHolder.birthDate = (TextView) rowView.findViewById(R.id.birth_date);
viewHolder.expDate = (TextView) rowView.findViewById(R.id.exp_date);
viewHolder.flag = (ImageView) rowView.findViewById(R.id.passport_flag);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
EPassport rowPassport = this.ePassportsList.get(position);
holder.expDate.setText(DATE_OF_EXPIRY + rowPassport.getDateOfExpiry());
holder.birthDate.setText(DATE_OF_BIRTH + rowPassport.getDateOfBirth());
holder.documentNumber.setText(DOCUMENT_NUMBER + rowPassport.getDocumentNumber());
if (rowPassport.getCountryCode() != null) {
String alpha2CountryCode = null;
try {
alpha2CountryCode = ISO3166Database.getAlpha2Code(rowPassport.getCountryCode());
} catch (IllegalCountryCodeException e) {
Log.e(TAG, e.getLocalizedMessage());
}
holder.flag.setImageResource(
getContext()
.getResources()
.getIdentifier(alpha2CountryCode, "drawable", getContext().getPackageName()));
}
return rowView;
}
}
I work with Android Studio 1.4 and the 'Design' tab of my row_layout.xml looks exactly how I want it to be.
When I run the application however, of the three text fields only one shows up on the screen.
I can't figure out the why. If anyone would like to give me a hand with this one, it would be greatly appreciated.
Image of the row layout as rendered by android studio:
(Click image to enlarge)
Image as shown on the screen:
Try to use this as row:
<?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"
android:background="#FF664747"
android:padding="8dp">
<TextView
android:id="#+id/documentNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Document number: " />
<TextView
android:id="#+id/birthDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/documentNumber"
android:paddingTop="12dp"
android:text="Birth date: " />
<TextView
android:id="#+id/expireDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/birthDate"
android:text="Expire date: " />
<ImageView
android:id="#+id/passportFlag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/documentNumber"
android:src="#android:drawable/ic_dialog_email" />
</RelativeLayout>
Just change your data and color.
I've been having some troubles with excess whitespace at the bottom of ListView items. Example with white/negative space marked with red arrows at http://i.stack.imgur.com/wpm7a.png
Here's my layout 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: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="com.thereversecookbook.ResultsList" >
<ListView
android:id="#+id/results_list_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
And my list item XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- cooking time -->
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="false"
android:longClickable="false"
android:paddingBottom="50dp"
android:textColor="#CC0033"
android:textSize="16sp" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerVertical="true"
android:clickable="false"
android:longClickable="false"
android:maxHeight="50dp"
android:maxWidth="50dp"
android:src="#drawable/ic_clock" />
<TextView
android:id="#+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/icon"
android:layout_centerVertical="true"
android:clickable="false"
android:longClickable="false"
android:textColor="#3399FF"
android:textSize="14sp" />
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false"
android:isIndicator="true"
android:longClickable="false"
android:scaleX="0.5"
android:scaleY="0.5"/>
</RelativeLayout>
And CustomListAdapter:
public class CustomListViewAdapter extends ArrayAdapter<RowItem> {
Context context;
public CustomListViewAdapter(Context context, int resourceId, List<RowItem> items) {
super(context, resourceId, items);
this.context = context;
}
/*private view holder class*/
private class ViewHolder {
ImageView imageView;
TextView txtTitle;
TextView txtCookingTime;
RatingBar ratingBar;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
RowItem rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.txtCookingTime = (TextView) convertView.findViewById(R.id.desc);
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
holder.ratingBar = (RatingBar) convertView.findViewById(R.id.ratingBar1);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.txtCookingTime.setText(rowItem.getCookingTime());
holder.txtTitle.setText(rowItem.getTitle());
//holder.imageView.setImageResource(rowItem.getImageId());
holder.ratingBar.setRating(rowItem.getRating());
holder.ratingBar.setStepSize((float)0.5);
return convertView;
}
}
Anyone have any ideas what could be causing this? Many thanks!
convertView = mInflater.inflate(R.layout.list_item, null);
Bzzzt. Don't use that inflate() method. You want to use the three-parameter version, passing in your convertView ("the inflated widgets will eventually be a child of this...") and false ("...but don't make them be children of it right away"):
convertView = mInflater.inflate(R.layout.list_item, parent, false);
That's particularly important in your case, as RelativeLayout gets weird if it's the root container of your layout file and you don't use this version of the inflate() method.
You can read more about this in Dave Smith's "Layout Inflation as Intended" blog post.
I am working on app with ListView with buttons on list item.
It's working fine but I can't find way to make buttons on items clickable.
I want to make this Silver arrows clickable. How can I do that?
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow"
android:layout_alignParentRight="true"
android:onClick="btnclick"
android:layout_centerVertical="true"/>
How can I make this to be different, like ItemClickListener with position?
Here is my Adapter
class DAdapter extends ArrayAdapter<String>{
Context context;
int [] images;
String[] titleArray;
DAdapter(Context c, String [] titles, int imgs[])
{
super(c,R.layout.single_row, R.id.title,titles);
this.context=c;
this.images=imgs;
this.titleArray=titles;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
if (row==null) { LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.single_row, parent,false);
}
ImageView myImage=(ImageView) row.findViewById(R.id.list_image);
TextView myTitle=(TextView) row.findViewById(R.id.title);
myImage.setImageResource(images[position]);
myTitle.setText(titleArray[position]);
return row;
I'm not sure if I should add whole code but if its needed please tell me.
single_row.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<LinearLayout android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="#drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="#+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/thumbnail"
android:layout_toRightOf="#+id/thumbnail"
android:text=""
android:textColor="#040404"
android:typeface="sans"
android:textSize="15sp"
android:textStyle="bold"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow"
android:layout_alignParentRight="true"
android:onClick="btnclick"
android:layout_centerVertical="true"/>
</RelativeLayout>
First add id to your ImageView like..
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow"
android:layout_alignParentRight="true"
android:id="#+id/arrowImage"
android:onClick="btnclick"
android:layout_centerVertical="true"/>
then get the ImageView and write listener ..change your getView like..
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.single_row, parent, false);
}
ImageView myImage = (ImageView) row.findViewById(R.id.list_image);
TextView myTitle = (TextView) row.findViewById(R.id.title);
myImage.setImageResource(images[position]);
myTitle.setText(titleArray[position]);
ImageView arrowImage = (ImageView) row.findViewById(R.id.arrowImage);
arrowImage.setTag(position);
arrowImage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int clickedposition=(Integer) v.getTag();
//Write your Activity launch code here..
}
});
return row;
}
You should set a general onclick handler for the image view. Then while doing the job in the onclick listener just check its parent to know the parent of this button. And if you want some custom style for this arrow to be shown, you can use a button instead of imageButton and set its background to an xml file to make it dynamic.
Is this enough?
I am displaying a listview using an arrayadapter. for each listitem i inflate the same xml file.i am able to display the listview fine.but now i have another requirement. i want to add some more view programatically to the same xml file that i am inflating for each list item. but when i try to do that i am not getting any error. but somehow the view i added programatically is not showing up...can anyone please help me. below is the code for the xml layout and for the arrayadapter
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/listitemcolor"
android:padding="10dip">
<LinearLayout
android:layout_weight="1.0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:textColor="#android:color/black"
android:id="#+id/locationitem_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:layout_marginTop="5dip"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:drawableLeft="#drawable/like"
android:textColor="#008000"
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Likes"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:textColor="#008000"
android:layout_marginLeft="5dip"
android:id="#+id/number_of_likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:drawableLeft="#drawable/dislike"
android:textColor="#FF0000"
android:layout_marginLeft="10dip"
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dislikes"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:textColor="#FF0000"
android:layout_marginLeft="5dip"
android:id="#+id/number_of_dislikes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
This is the code for arrayadapter:
public class LocationItemAdapter extends ArrayAdapter<LocationItem> {
private Context context;
private ArrayList<LocationItem> items;
public LocationItemAdapter(Context context,
List<LocationItem> objects) {
super(context, R.layout.locationitem_listview_element, objects);
this.context = context;
items = (ArrayList<LocationItem>) objects;
}
/* (non-Javadoc)
* #see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
*/
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowview = null;
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowview = inflater.inflate(R.layout.locationitem_listview_element, null);
}
else
{
rowview = convertView;
}
((TextView)rowview.findViewById(R.id.locationitem_name)).setText(items.get(position).getName());
((TextView)rowview.findViewById(R.id.number_of_likes)).setText(String.valueOf(items.get(position).getLikes()));
((TextView)rowview.findViewById(R.id.number_of_dislikes)).setText(String.valueOf(items.get(position).getDislikes()));
LayoutInflater inflater1 = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tv = new TextView(context);
//TextView tv = (TextView)inflater1.inflate(R.layout.sample, null);
tv.setText("My name is blah");
tv.setTextColor(R.color.black);
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
//tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
LinearLayout ll = (LinearLayout)rowview.findViewById(R.id.placeholder);
//((LinearLayout)rowview.findViewById(R.id.placeholder)).addView(tv);
ll.addView(tv);
rowview.setTag(items.get(position));
return rowview;
}
}
That looks correct to me. Perhaps the embed is successful but ll takes up no space on the screen? Can you verify that placeholder takes up some amount of visible space on the screen by setting it's background color to hot pink or something?
I have created an application which is a simple form. Users will enter username data and password into each editText pair provided.
My problem comes with extracting this data. Normally, I would extract by the "#id/" value assigned to each editText, but as I am using an adapter and a separate xml file for the row this is not possible, as each editText has the same id.
Does anyone have an idea how I might go about doing this?
Main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button
android:id="#+id/cancelbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:paddingLeft="50dp"
android:paddingRight="50dp"/>
<Button
android:id="#+id/submitbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/submit"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:paddingLeft="50dp"
android:paddingRight="50dp"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/list"
android:layout_alignParentTop="true"
android:layout_above="#id/cancelbutton" />
list.xml : used for individual row
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:src="#drawable/g" >
</ImageView>
<EditText
android:id="#+id/firstLine"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="email"
>
</EditText>
<EditText
android:id="#+id/secondLine"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignRight="#id/logo"
android:layout_alignParentRight="true"
android:layout_below="#id/firstLine"
android:text="password"
>
</EditText>
public class ColorAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public SocialSiteAdapter(Context context, String[] values) {
super(context, R.layout.list, values);
this.context = context;
this.values = values;
}
// GetView does what exactly..?
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list, parent, false);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
// Change icon based on name
String s = values[position];
System.out.println(s);
if (s.equals("Blue")) {
imageView.setImageResource(R.drawable.b);
} else if (s.equals("Green")) {
imageView.setImageResource(R.drawable.g);
} else if (s.equals("Red")) {
imageView.setImageResource(R.drawable.r);
} else if (s.equals("Yellow")) {
imageView.setImageResource(R.drawable.y);
} else {
imageView.setImageResource(R.drawable.ic_launcher);
}
return rowView;
}
}
You need to first select the row and then inside the row select the EditTexts by their known #id
To list the entries you could go like:
ListView listView = getListView();
for (int i = 0; i < listView.getCount(); i++) {
Layout row = (Layout) listView.getItemAtPosition(i); /// XXX
EditText t = (EditText) row.findViewById(R.id.firstLine);
// ...
}
You need to check by yourself in the line with XXX what the getItem.. call returns and change accordingly.