Saturday, July 2, 2011

[android-developers] Re: Three line ListView question

If I understand your question right, probably you need your own custom
adapter for the listview.

Something like below might work in your case. I copy-paste parts from
my code, so you'll need to tweak it to make it run.

Sketch of your listview mylistlayout.xml.

<LinearLayout
android:orientation="vertical"
... >
<TextView
"@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<!-- Set the size font etc of text -->
... />
<TextView
"@+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<!-- Set the size font etc of text -->
... />
<ProgressBar
"@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
... />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/png_name_of_the_thin_line"
... />
</LinearLayout>


Then, in your code something like:

public class MyListView extends ListActivity
{
private class ListItem
{
public String text1;
public String text2;
public int progress;
// Other members if necessary
}
ArrayList<ListItem> my_list = new ArrayList<ListItem>();


@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setListAdapter(new MyCustomAdapter(this));

// Other code you need in onCreate comes here
}

// Probably you'll also have methods of this sort

private void AddToListView()
{
ListItem listItem = new ListItem();
// listItem.text1 = ...
// etc etc

getListAdapter().add(listItem);
my_list.add(listItem);
}

// BEWARE: Think very carefully how frequently you should
// update your progress bars. Updating them very frequently
// will make your application extremely slow.
private void UpdateProgressBar(int i)
{
// Probably something like this
ListItem listItem = listItem.get(i);
// listItem.progress = ...

getListAdapter().notifyDataSetChanged();
}


class MyCustomAdapter extends ArrayAdapter<ListItem>
{
Activity context;

MyCustomAdapter(Activity context)
{
super(context, R.layout.mylistlayout, new
ArrayList<ListItem>());
this.context = context;
}

public View getView(int position, View convertView, ViewGroup
parent)
{
View row = convertView;

if (null == row)
{
LayoutInflater inflater = this.context.getLayoutInflater();
row = inflater.inflate(R.layout.mylistlayout, null);
}

ListItem listItem = getItem(position);

TextView text=(TextView)row.findViewById(R.id.text1);
text.setText(listItem.text1);

// Similarly set values for text2 and progress_bar

return(row);
}

}

};

I hope this helps you.
____________________________

Final note to others:
This is an Android question a novice asked. Don't make fun of it,
because it's not funny. If you don't know or don't wish to write a
decent answer, don't write your spam just to advertise the link to
your published application. Probably you have published a great
application which deserves respect but don't spam the list just to
advertise it. Post the link to it only when you have something to add.

----------
Ali Chousein
Geo-Filtered Assistant
http://geo-filtered-assistant.blogspot.com/


On Jul 2, 6:51 am, arudzki <tony.rud...@gmail.com> wrote:
> All,
>
> I would like to know if something is possible, and if I could get a
> hint or two on how to do it.  I want to use a ListView where each
> group that can be selected consists of two lines of text and below
> that a progress bar or a colored line.  The point of the screen is to
> keep track of the amount of time until something occurs.  The two text
> lines would contain the name of the item or event, the second line,
> when it started (a date) and the progress bar/colored line would
> graphically show how much time until that event or timer
> expired(starts off at say, 30 pixels equaling 30 days, and every day
> one pixel is removed and the line gets shorter).
>
> I've done two line ListViews, but how do I add a really thin progress
> bar or colored line as a third line in each of the ListView items?
>
> Thanks for the help
>
> Tony

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment