ListView won't show up anymore - android

I use the following main.xml for my app.
<?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:id="#+id/toplinear">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linear">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Previous"
android:id="#+id/previous"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/next"
android:layout_toRightOf="#id/previous"
android:layout_weight="1"
/>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/android:list"
android:layout_weight="10"
/>
</LinearLayout>
I want to have 2 buttons at the top, previous and next and my listview with custom adapter below it. Few days ago I had only my ListView showing, going over the buttons. Now I seem to be stuck on the other side, where my listview doesn't show while my buttons do.
My activity extends on ListActivity and uses this code to fill it with a customadapter.
ListView lv = getListView();
lv.setAdapter(new MyCustomAdapter(this, R.layout.custom_list, nameResults));
public class MyCustomAdapter extends ArrayAdapter<String> {
private String[] nameResults;
private Context context;
public MyCustomAdapter(Context context, int textViewResourceId,
String[] names) {
super(context, textViewResourceId, names);
this.context = context;
nameResults = names;
}
#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.custom_list, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.Name);
label.setText(nameResults[position]);
TextView descr = (TextView) row.findViewById(R.id.Description);
descr.setText(linkedResults.get(nameResults[position]));
return row;
}
}
I tried using "lv.addHeaderView(previous);" but that only gave me vague ClassCastExceptions about LayoutParams.
I think my problem is currently in my main.xml, as the Layout tab in Eclipse of it won't show the ListView either. It knows its there as it shows up in the outline tab, but the visual representation doesn't give it a red outline when I select it.
For completeness, my custom_list (aka row) layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Name"
android:textColor="#000000"
android:textStyle="bold"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Description"
android:textColor="#000000"
/>
</LinearLayout>

I'm modified your main.xml a bit - added orientation and took off the layout_weight for the listview - hopefully this fixes that problem.
<?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="vertical"
android:id="#+id/toplinear">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linear">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Previous"
android:id="#+id/previous"
android:layout_weight="1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/next"
android:layout_toRightOf="#id/previous"
android:layout_weight="1"
/>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/android:list"
/>
</LinearLayout>

Related

I can't make a two listview [duplicate]

This question already has answers here:
How to display a two column ListView in Android?
(5 answers)
Closed 7 years ago.
Hi I'd like to made a 2 vertical listview to show some data from server.
But it's getting a lot of errors..
Please help me to fix it.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView android:id="#+id/data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/data view"
/>
<ListView
android:id="#+id/date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:stackFromBottom="true" >
</ListView>
<ListView
android:id="#+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:stackFromBottom="true" >
</ListView>
</LinearLayout>
What I'm after:
I will give you an answer that resembles what you want, but you are free to tweak it.
Just to note: RecyclerView is mostly used nowadays, but since you asked for a ListView example I will give you an example with a ListView.
First of all you need to specify one ListView in your main activity's layout xml file. You also need a second layout for each item in the ListView. This second layout is going to have two TexViews. The first for Date and the second for Result. And finally you need an adapter for that ListView, which is responsible for inflating each item's (of the list) layoout, keep your list data, etc.
Here is a sample activity_main.xml layout. I added two views to resemble the lines between TextViews:
<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:padding="16dp"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Date"
android:id="#+id/textViewDate"
android:gravity="center"
android:layout_toLeftOf="#+id/view2"
android:layout_toStartOf="#+id/view2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
android:id="#+id/view1"
android:layout_alignBottom="#+id/textViewDate" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/view2"
android:layout_alignBottom="#+id/textViewDate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Result"
android:id="#+id/textViewResult"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/view2"
android:layout_toEndOf="#+id/view2" />
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:layout_below="#+id/relativeLayout">
</ListView>
</RelativeLayout>
The list_item.xml layout for each item in the list:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Date"
android:id="#+id/textViewDate"
android:gravity="center"
android:layout_toLeftOf="#+id/view"
android:layout_toStartOf="#+id/view"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/view"
android:layout_alignBottom="#+id/textViewDate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Result"
android:id="#+id/textViewResult"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/view"
android:layout_toEndOf="#+id/view"
android:layout_alignBottom="#+id/textViewDate" />
</RelativeLayout>
Then a class for your custom item that holds a date and a result.
public class MyItem {
public GregorianCalendar date;
public String result;
public MyItem(GregorianCalendar date, String result){
this.date = date;
this.result = result;
}
}
and the adapter (here ArrayAdapter):
public class MyAdapter extends ArrayAdapter<MyItem> {
private final Context mContext;
private MyItem[] mItems;
public MyAdapter(Context context, MyItem[] items) {
super(context, -1, items);
mContext = context;
mItems = items;
}
#Override
public View getView(int position,View view,ViewGroup parent) {
View rowView = view;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.list_item, null, true);
}
TextView textViewDate = (TextView) rowView.findViewById(R.id.textViewDate);
TextView textViewResult = (TextView) rowView.findViewById(R.id.textViewResult);
textViewDate.setText(mItems[position].date.getTime().toString());
textViewResult.setText(mItems[position].result);
return rowView;
}
}
Finally in your activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyItem[] items = {new MyItem(new GregorianCalendar(2014, 1, 1), "Ok"),
new MyItem(new GregorianCalendar(2014, 2, 3), "Not ok"),
new MyItem(new GregorianCalendar(2015, 3, 3), "Ok"),
new MyItem(new GregorianCalendar(2015, 5, 7), "Warning"),
new MyItem(new GregorianCalendar(2016, 7, 1), "Ok")};
MyAdapter adapter = new MyAdapter(this, items);
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
}

Customized ListView with TextView, TextView, RadioGroup in Android

I'm developing an application with ListView for Student Marklist creation.
In this application, the List have 10 students. There are four grades provided for the exam which was conducted to those Students. One student can adapt only one grade from the four.
The teacher will assign the grade to the student in ListView.
My xml file Studentlist.xml is as follow:
<?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" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
and my row.xml file is as follow:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="500dp"
android:layout_height="fill_parent"
android:padding="10dp" >
<TableRow>
<TextView
android:id="#+id/SNo"
style="#style/text"
android:layout_width="40dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/StudNo"
style="#style/text"
android:layout_width="80dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/StudName"
style="#style/text"
android:layout_width="180dp"
android:layout_height="wrap_content" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:checked="true" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="40dp"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="40dp"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="40dp"
android:layout_height="wrap_content" />
</RadioGroup>
</TableRow>
Now I'm trying for the output in the form of:
1 0001 AAAA <RadioButton1> <RadioButton2> <RadioButton3> <RadioButton4>
2 0002 BBBB <RadioButton1> <RadioButton2> <RadioButton3> <RadioButton4>
How can I use the Adapter functionalities?
ArrayAdapter<String,String,String,RadiGroup> studList=new ArrayAdapter<String,String,String,RadiGroup>();
Can I use like this, and how to develop the customized Adapter for the ListView?
Suggest me for the best solution!
This is a sample example of custom adapter for listview. Modify it as your need:
XML layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/main"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Header -->
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black" >
<TextView
android:id="#+id/item2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:height="30dip"
android:text="Latest News - Your Healing Place"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
android:width="100dip" />
<TextView
android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:height="30dip"
android:width="20dip" />
</LinearLayout>
<View android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<LinearLayout android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/black" >
</ListView>
</LinearLayout>
</LinearLayout>
news.java :
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
String[] from = new String[] {"details", "date"};
int[] to = new int[] { R.id.item1, R.id.item2};
ListView lv= (ListView)findViewById(R.id.listview);
HashMap<String, String> map = new HashMap<String, String>();
map.put("details", "This is a sample message");
map.put("date", "24-07-2003");
fillMaps.add(map);
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
lv.setAdapter(adapter);
You can use a class inheriting from ArrayAdapter, and overriding its getView() method.
public class StudentAdapter extends ArrayAdapter<Student> {
protected LayoutInflater inflater;
public StudentAdapter(final Context context) {
super(context, 0);
inflater = (LayoutInflater) ((Context) context)
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent) {
// Note: You should optimize here with re-using convertView
View rowView = inflater.inflate(R.layout.user_address_row_layout,
parent, false);
TextView sNo = (TextView) rowView.findViewById(R.id.sNo);
sNo.setText(getItem(position).number);
// same for every field of the row
// ...
return rowView;
}
}

cant see my footer with ListActivity

I am trying to do footer to my custom list but still cant work it out.
My aim is just to add some button to end of the list.
I tried this:
adapter = new GeneralRssAdapter(this,R.layout.titlesrss, data);
LayoutInflater inflater = getLayoutInflater();
lv.addFooterView( inflater.inflate( R.layout.footer_layout, null ), null, false);
lv.setAdapter(adapter);
but still cant see any footer.
Heres my 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:id="#+id/linearLa"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/iconremove"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_margin="5dip"
android:scaleType="centerCrop"
android:src="#drawable/delete"
android:visibility="gone" />
<ImageView
android:id="#+id/iconfav"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_margin="5dip"
android:scaleType="centerCrop"
android:src="#drawable/rss" />
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal|center"
android:layout_margin="5dip"
android:layout_weight="1"
android:textSize="20dip" />
</LinearLayout>
<ListView android:id="#+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
and the footer:
<?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" >
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.20"
android:src="#drawable/tutorialrss"
/>
</LinearLayout>
hope you can HELP me:)
try this
adapter = new GeneralRssAdapter(this,R.layout.titlesrss, data);
LayoutInflater mInflater = (LayoutInflater)getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View footer = mInflater.inflate(R.layout.footer_layout, null);
choicelist.addFooterView(footer);
choicelist.setAdapter(adapter);
i have edited this 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="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/tutorialrss"
/>
</LinearLayout>
for me its working plz check once.
adapter = new ListAdapter(this, data);
ListView lvMain = (ListView) findViewById(R.id.list);
LayoutInflater mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View footer = mInflater.inflate(R.layout.footer, null);
lvMain.addFooterView(footer);
lvMain.setAdapter(adapter);
What I do is set my footer/header in setContentView() then uselist xml in adapter. I don't normally like one line answers but that's all I do

custom scrollview not appearing

I have a custom ScrollView that works fine if it is the only thing in the emulator.
For example, this works fine:
public class Timeline2Activity extends Activity {
private TimelineView tlv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tlv = new TimelineView(this);
setContentView(tlv);
}
}
But if I first add widgets then it fails to appear. I've searched and experimented for 2 days and nothing works.
Here is the class declaration of the custom ScrollView:
public class TimelineView extends ScrollView implements OnTouchListener {
And here are the constructors:
public TimelineView(Context context) {
super(context);
this.setOnTouchListener(this);
setVisibility(VISIBLE);
}
//the following constructor is needed to inflate the view from XML
public TimelineView(Context context, AttributeSet ats) {
super(context,ats);
this.setOnTouchListener(this);
setVisibility(VISIBLE);
}
Here is the main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="#+id/zoomall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom All" />
<Button
android:id="#+id/zoomout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="#+id/zoomin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Spinner
android:id="#+id/category_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/category_prompt"
/>
</LinearLayout>
<com.projects.timeline2.TimelineView
android:id="#+id/timeline_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
And here is the main program:
public class Timeline2Activity extends Activity {
private TimelineView tlv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//tlv = new TimelineView(this);
//setContentView(tlv);
setContentView(R.layout.main);
Spinner spinnerCategory = (Spinner) findViewById(R.id.category_spinner);
ArrayAdapter<CharSequence> adapterCategory = ArrayAdapter.createFromResource(
this, R.array.categories, android.R.layout.simple_spinner_item);
adapterCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCategory.setAdapter(adapterCategory);
spinnerCategory.setOnItemSelectedListener(new MyOnItemSelectedListener());
//TimelineView tlv = (TimelineView) findViewById(R.id.timeline_view);
//ViewGroup container = (ViewGroup) findViewById(R.id.container);
//container.addView(tlv);
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(), "The selection is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
}
The lines commented out are stuff I've tried but didn't work either.
This code correctly puts 3 buttons and a spinner in a horizontal row across the top. But TimelineView fails to appear below them. I know that TimelineView is running because I can see debugging output in the LogCat that I put in.
I'm at my wits end and hope someone can shed some light. This seems like a common fundamental need and sure deserves a google tutorial.
You are using LinearLayout and you have used android:layout_height="fill_parent" to the first element so the first element will fill the whole screen height and there will be no space for the second element (com.projects.timeline2.TimelineView) thats why you are unable to see second element.
Use Relative Layout instead. and mention android:layout_alignParentBottom="true" for second element so that it will always stay to the buttom of the screen and align the first element to the above of second by putting android:layout_above to first element
Your XML will be
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.projects.timeline2.TimelineView
android:id="#+id/timeline_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_above="#+id/timeline_view">
<Button
android:id="#+id/zoomall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom All" />
<Button
android:id="#+id/zoomout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="#+id/zoomin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Spinner
android:id="#+id/category_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="category_prompt"
/>
</LinearLayout>
</RelativeLayout>
I think you should change TimeLine's layout height to fill_parent in xml, or add some content to it.
I finally got it. Here is the main.xml that worked.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
>
<Button
android:id="#+id/zoomall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom All" />
<Button
android:id="#+id/zoomout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="#+id/zoomin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Spinner
android:id="#+id/category_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<com.projects.timeline2.TimelineView
android:id="#+id/timeline_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_below="#id/buttons"
/>
</RelativeLayout>
Thanks everyone for getting me going in the right direction!

Highlight TextView item in the list

I have the ListView:
<?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:background="#drawable/background"
android:orientation="vertical">
<ImageView
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:src="#drawable/tab"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"></ImageView>
<TextView
android:id="#+id/subcat"
android:background="#b9cd4a"
android:layout_width="fill_parent"
android:textColor="#fff"
android:textStyle="bold"
android:layout_height="35dp"
android:textSize="18dp"
android:paddingLeft="10dp"
android:paddingTop="6dp"
android:text="Choose Location"></TextView>
<ListView
android:id="#+id/sub_catlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="#color/black"></ListView>
</LinearLayout>
And I inflate the list using TextView layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="#fff"
android:orientation="vertical"
android:layout_height="65dp" >
<TextView
android:text="#+id/albumDetails"
android:id="#+id/albumDetails"
android:textColor="#000"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textSize="16dp"
android:layout_width="wrap_content"
android:paddingTop="8dp"
android:layout_height="45dp"></TextView>
</LinearLayout>
The problem is when I click list item, I don't see any highlight. I need to show the highlight when the user click the item. How can I do that?
TextView is intercept click events from ListView. Set attributes
android:focusable="false"
android:clickable="false"
to the list's TextView.
In Custom Listview below code used.
TextViewClick.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
int count = listview.getChildCount();
for (int i = 0; i < count; i++) {
View v = listview.getChildAt(i);
TextView tx = (TextView) v.findViewById(R.id.txt1);
txt1.setBackgroundColor(Color.RED);
}
txt1.setBackgroundColor(Color.GREEN);
}
});
I think the issue may be in android:listSelector="#color/black", remove this line
Sample ListView
<ListView
android:id="#+id/nativecontacts_contacts_ListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:background="#color/White"
android:divider="#drawable/menu_line"
android:cacheColorHint="#00000000"
android:clickable="true" />

Categories

Resources