Proper usage of twoLineListItem Android - android

I am new to development on android and trying to create a list that has a bold header
and a smaller description for each item.
Like the one shown here (sorry can't post images yet):
http://i.stack.imgur.com/UVqzq.png
This is the XML that I have to start with:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TwoLineListItem android:layout_width="fill_parent"
android:layout_height="wrap_content" android:mode="twoLine">
<TextView android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#android:id/text1" android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:layout_below="#android:id/text1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_alignLeft="#android:id/text1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#android:id/text2" />
</TwoLineListItem>
</LinearLayout>
Is there a way to populate the list from an array in another xml file? If not how would I populate a list like this from the Java code? Like I said I'm new to development, so I'm probably way off. Thanks for any input!

You use a listview http://developer.android.com/reference/android/widget/ListView.html

In the case of an Array of Objects, you just have to implement your own adapter.
It can work for a TwoLineListItem or any other custom layout.
For example, if I have a list of items of the following type :
public class ProfileItem {
public String host, name, tag;
public ProfileItem(String host, String name, String tag) {
this.host = host;
this.name = name;
this.tag = tag;
}
#Override
public String toString() {
return name+"#"+tag;
}
}
Then I create the following adapter :
public class ProfileItemAdapter extends ArrayAdapter<ProfileItem> {
private Context context;
private int layoutResourceId;
private List<ProfileItem> objects = null;
public ProfileItemAdapter(Context context, int layoutResourceId, List<ProfileItem> objects) {
super(context, layoutResourceId, objects);
this.context = context;
this.layoutResourceId = layoutResourceId;
this.objects = objects;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
v = inflater.inflate(layoutResourceId, parent, false);
}
ProfileItem item = objects.get(position);
TextView titletext = (TextView)v.findViewById(android.R.id.text1);
titletext.setText(item.toString());
TextView mainsmalltext = (TextView)v.findViewById(android.R.id.text2);
mainsmalltext.setText(item.host);
return v;
}
}
Then everything is in place, in my activity (or fragment), I just have to set this adapter in the onCreate method :
setListAdapter(new ProfileItemAdapter(getActivity(),
android.R.layout.two_line_list_item, // or my own custom layout
ProfileListContent.ITEMS));

I have a similar implementation, but instead of a 2 line listview, I have 3 lines.
This is the XML:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#111111"
android:textSize="17sp"
android:textStyle="bold"
android:text="PROJECT NAME"
android:typeface="monospace"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:gravity="left|center" >
</TextView>
<TextView
android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#111111"
android:text="Selected Type"
android:textSize="16sp"
android:paddingBottom="1dp"
android:paddingTop="1dp"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
</TextView>
<TextView
android:id="#+id/text3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#111111"
android:textSize="16sp"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="Project Description" >
</TextView>
</LinearLayout>
And this is the JAVA code for filling the lines with data returned from a DB. This code is in the onCreate() method:
String[] fields = new String[] { db.TABLE_PRJ_NAME, db.TABLE_PRJ_TYPE, db.TABLE_PRJ_DESC };
int[] views = new int[] { R.id.text1, R.id.text2, R.id.text3 };
c = db.getAllProjects();
startManagingCursor(c);
// Set the ListView
SimpleCursorAdapter prjName = new SimpleCursorAdapter(
this,
R.layout.project_list_rows,
//android.R.layout.simple_list_item_1,
c, fields, views);
setListAdapter(prjName);

Related

How to put titles for each field of a ListView item in Android

I have a Listview with a custom adapter , which displays person's data like
Barak Obama 2008
But I want to put a header with Name Surname Date but properly alligned
A draft example:
ListView Items with titles
How Can I achieve this?
thank you
Custom ListView, All what you need, A xml layout for row with adapter and listview
check out this link explain Custom listview
https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView
You can use TableLayout to show your Data as your requirement. I've replicated your demand. Here are the codes.
1) MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lstview=(ListView)findViewById(R.id.listView);
// Inflate header view
ViewGroup headerView = (ViewGroup)getLayoutInflater().inflate(R.layout.header_layout, lstview,false);
// Add header view to the ListView
lstview.addHeaderView(headerView);
// Get the string array defined in strings.xml file
String[] date = {"29-03-17", "29-03-17"};
String[] amount = {"5", "2"};
String[] dept = {"14", "4"};
// Create an adapter to bind data to the ListView
CustomListViewAdapter adapter=new CustomListViewAdapter(this,R.layout.row_listview, R.id.tvDate, date, amount, dept);
// Bind data to the ListView
lstview.setAdapter(adapter);
}
2) CustomListViewAdapter.java
public class CustomListViewAdapter extends ArrayAdapter<String> {
int groupid;
String[] date;
String[] amount;
String[] dept;
ArrayList<String> desc;
Context context;
public CustomListViewAdapter(Context context, int vg, int id, String[] date, String[] amount, String[] dept){
super(context,vg, id, date);
this.context=context;
groupid=vg;
this.date=date;
this.amount=amount;
this.dept=dept;
}
// Hold views of the ListView to improve its scrolling performance
static class ViewHolder {
public TextView tvDate;
public TextView tvAmount;
public TextView tvDept;
}
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// Inflate the rowlayout.xml file if convertView is null
if(rowView==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView= inflater.inflate(groupid, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.tvDate= (TextView) rowView.findViewById(R.id.tvDate);
viewHolder.tvAmount= (TextView) rowView.findViewById(R.id.tvAmount);
viewHolder.tvDept= (TextView) rowView.findViewById(R.id.tvDept);
rowView.setTag(viewHolder);
}
// Set text to each TextView of ListView item
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.tvDate.setText(date[position]);
holder.tvAmount.setText(amount[position]);
holder.tvDept.setText(dept[position]);
return rowView;
}
}
3) HeaderLayout (header_layout.xml)
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/tvDate"
android:layout_column="0"
android:padding="10sp"
android:gravity="left"
android:layout_span="1"
android:text="Date"
android:layout_gravity="center">
</TextView>
<TextView
android:id="#+id/tvAmount"
android:layout_column="1"
android:padding="10sp"
android:gravity="left"
android:layout_span="1"
android:text="Amount"
android:layout_gravity="center">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvDept"
android:layout_column="2"
android:layout_span="1"
android:text="Dept"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvDelete"
android:layout_column="3"
android:layout_span="1"
android:text="Delete"
android:layout_gravity="center" />
</TableRow>
</TableLayout>
4) RowLayout for each ListView row (row_listview.xml)
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvDate"
android:layout_column="0"
android:padding="10sp"
android:gravity="left"
android:layout_span="1"
android:text="Date"
android:layout_gravity="center">
</TextView>
<TextView
android:id="#+id/tvAmount"
android:layout_column="1"
android:padding="10sp"
android:gravity="left"
android:layout_span="1"
android:text="Amount"
android:layout_gravity="center">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvDept"
android:layout_column="2"
android:layout_span="1"
android:text="Dept"
android:layout_gravity="center" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_column="3"
android:layout_span="1"
android:src="#android:drawable/ic_delete" />
</TableRow>
</TableLayout>
5) Output:
Hope this helps.

Is there a way to display TableLayout in ListView

I have 10+ tables created in xml Tablelayout and i'm trying to
put them in ListView rather than in a ScrollView .
Tables are not editable and just for info... How to put them as
data source in Adapter or i need to Inflate or what? tnx and sorry for noobish q..
You need to create custom Adapter for the ListView(please search this). With the adapter you need to create ListView item layout, where you can define your table for each row in the List View.
Hope this helps. :)
You can do it by simply adding TableLayout to ListView row layout xml.
Example from my current application:
public class DistributorsListAdapter extends ArrayAdapter<String>{
private final Context context;
private final int rowResourceId;
private final JSONArray data;
public DistributorsListAdapter(Context context, int rowResourceId, String[] ids, JSONArray data) {
super(context, rowResourceId, ids);
this.context = context;
this.rowResourceId = rowResourceId;
this.data = data;
}
#Override
public View getView(int position, View v, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(rowResourceId, parent, false);
try {
JSONObject rowData = data.getJSONObject(position);
// Заполняем данными строку списка
setHTMLData(rowView, rowData, "name", R.id.distributor_table_title );
setHTMLData(rowView, rowData, "address", R.id.distributor_address );
setData(rowView, rowData, "website", R.id.distributor_website );
setData(rowView, rowData, "phone", R.id.distributor_phone );
setData(rowView, rowData, "fax", R.id.distributor_fax );
setData(rowView, rowData, "email", R.id.distributor_email );
} catch (JSONException e) {
e.printStackTrace();
}
return rowView;
}
private void setData(View v, JSONObject data, String key, int textViewId) throws JSONException{
TextView tv = (TextView) v.findViewById(textViewId);
tv.setText(data.getString(key));
}
private void setHTMLData(View v, JSONObject data, String key, int textViewId) throws JSONException{
TextView tv = (TextView) v.findViewById(textViewId);
tv.setText( Html.fromHtml( data.getString(key) ) );
}
}
XML layout of a ListView row:
<?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"
android:paddingLeft="#dimen/activity_horizontal_padding"
android:paddingRight="#dimen/activity_horizontal_padding"
android:paddingBottom="#dimen/distributor_table_vertical_padding">
<TextView
android:id="#+id/distributor_table_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/distributor_table_vertical_padding"
android:gravity="center_horizontal"
android:textSize="#dimen/distributor_table_title_text_size"
android:textStyle="bold"/>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distributor_address"
android:textSize="#dimen/distributor_table_text_size"/>
<TextView
android:id="#+id/distributor_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/distributor_table_text_size"
android:layout_marginLeft="#dimen/distributor_table_columns_margin"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distributor_website"
android:textSize="#dimen/distributor_table_text_size"/>
<TextView
android:id="#+id/distributor_website"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/distributor_table_text_size"
android:layout_marginLeft="#dimen/distributor_table_columns_margin"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distributor_phone"
android:textSize="#dimen/distributor_table_text_size"/>
<TextView
android:id="#+id/distributor_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/distributor_table_text_size"
android:layout_marginLeft="#dimen/distributor_table_columns_margin"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distributor_fax"
android:textSize="#dimen/distributor_table_text_size"/>
<TextView
android:id="#+id/distributor_fax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/distributor_table_text_size"
android:layout_marginLeft="#dimen/distributor_table_columns_margin"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distributor_email"
android:textSize="#dimen/distributor_table_text_size"/>
<TextView
android:id="#+id/distributor_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/distributor_table_text_size"
android:layout_marginLeft="#dimen/distributor_table_columns_margin"/>
</TableRow>
</TableLayout>
</LinearLayout>

Populating a multicolumn listview without a hashmap

I have been reading about multicolumn listviews today. They seem to be what I need, but can't info info about how to populate them not using a hash map. All examples I have seen use a hash map to build the listview data adapter but this is too heavy when lot of data is implied. Is there anyway to populate a list view without a hash list?
All examples I have seen use something like this:
http://saigeethamn.blogspot.com.es/2010/04/custom-listview-android-developer.html
Yes it is possible. please Check out the code.
public class List_view_ArrayAdapter extends ArrayAdapter<String> {
private Context context;
private String[] name;
private String[] address;
private String[] rating;
private TextView nameTextView;
private TextView addressTextView;
private ImageView lisiconImageView;
private AppManagers appManagers;
public List_view_ArrayAdapter(Context context, String[] name,
String[] address, String[] rating) {
super(context, R.layout.list_layout, name);
this.context = context;
this.name = name;
this.address = address;
this.rating = rating;
appManagers = new AppManagers();
}
#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_layout, parent, false);
nameTextView = (TextView) rowView.findViewById(R.id.nameTextView);
addressTextView = (TextView) rowView.findViewById(R.id.addressTextView);
lisiconImageView = (ImageView) rowView
.findViewById(R.id.listiconImageView);
nameTextView.setText(name[position]);
addressTextView.setText(address[position]);
lisiconImageView.setImageDrawable(appManagers
.ImageOperations(rating[position]));
// imageView.setImageResource(imageid[position]);
return rowView;
}
}
Here is list_layout for this line "R.layout.list_layout"
<?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="wrap_content"
android:orientation="horizontal" android:background="#d9d9d9">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_marginBottom="5dp" android:layout_marginTop="5dp">
<ImageView
android:id="#+id/listiconImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:layout_marginLeft="5dp" android:gravity="center_vertical" android:layout_marginBottom="5dp" android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name : "
android:textColor="#2a170e" />
<TextView
android:id="#+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#2a170e" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address : "
android:textColor="#2a170e" />
<TextView
android:id="#+id/addressTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#2a170e" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Finaly you call it from your main Activity.
new List_view_ArrayAdapter arrayAdapter= new List_view_ArrayAdapter(context, appManagers.getNameArray(cafeandbarsList), name, address, rating);
listView.setAdapter(arrayAdapter);
I think it help you.
Thanks

Populating ScrollView with TextViews, Android Eclipse

Here is a segment from my .xml layout file:
<ScrollView
android:layout_width = "match_parent"
android:layout_height = "300dp" >
<TextView
android:id="#+id/statementdatetv"
android:layout_width="61dp"
android:layout_height="300dp"
android:text="DATE"
android:textSize="10dp" />
<TextView
android:id="#+id/statementlocationtv"
android:layout_width="95dp"
android:layout_height="300dp"
android:text="LOCATION" android:textSize="10dp"/>
<TextView
android:id="#+id/statementshoptypetv"
android:layout_width="95dp"
android:layout_height="300dp"
android:text="SHOPTYPE" android:textSize="10dp"/>
<TextView
android:id="#+id/statementpricetv"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="PRICE" android:layout_weight="1" android:textSize="10dp"/>
</ScrollView>
</LinearLayout>
The TextViews inside the ScrollView are to be populated from an SQL database. Everything worked fine before the ScrollView was added in, but afterwards it just came up with an error?
Unfortunately I don't know which error, is it just not possible to populate the values from an SQL database into a TextView which is inside a ScrollView?
The reason why I want to have a ScrollView is because a lot of Data could be outputted, and I want it to all be on the same page, therefore a ScrollView was the perfect (or so I thought) solution!
Thanks!
Try this, by using ListView
MyAdapter adapteres;
list = (ListView) findViewById(R.id.grp_list);
db = new DatabaseHelper(this);
contacts = db.getAllContacts();
adapteres = new MyAdapter(getBaseContext(), (ArrayList<Contact>) contacts);
list.setAdapter(adapteres);
and Here MyAdapter class:
public class MyAdapter extends BaseAdapter{
Button btn;
#SuppressWarnings("unused")
private Context context;
private ArrayList<Contact> contact;
private LayoutInflater mInflater;
public MyAdapter(Context context, ArrayList<Contact> contacts) {
this.context = context;
this.contact = contacts;
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return contact.size();
}
public Object getItem(int position) {
return contact.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int pos, View view, ViewGroup parent) {
if (view == null) {
view = mInflater.inflate(R.layout.group_row, parent, false);
}
Contact item = contact.get(pos);
TextView name = (TextView) view.findViewById(R.id.group_name);
name.setText(item.getName());
}
}
If you want to show some records from DB, probably the best way is using ListViev instead of ScrollView. You should find plenty of examples for ListViev, CursorAdapter on the net.
use a LinearLayout inside scroll view.
:)
<ScrollView
android:layout_width = "match_parent"
android:layout_height = "300dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/statementdatetv"
android:layout_width="61dp"
android:layout_height="300dp"
android:text="DATE"
android:textSize="10dp" />
<TextView
android:id="#+id/statementlocationtv"
android:layout_width="95dp"
android:layout_height="300dp"
android:text="LOCATION" android:textSize="10dp"/>
<TextView
android:id="#+id/statementshoptypetv"
android:layout_width="95dp"
android:layout_height="300dp"
android:text="SHOPTYPE" android:textSize="10dp"/>
<TextView
android:id="#+id/statementpricetv"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="PRICE" android:layout_weight="1" android:textSize="10dp"/>
</LinearLayout>
</ScrollView>

Android EditText: How to process data

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.

Categories

Resources