I am working on an application in Android that works with 2 screens. The firsts creen is simple, it has a TextView initialzed to "Not Set" and a Button. When the user clicks on the button, he/she is taken to the 2nd screen which is one big ListView. The ListView is a list of all highest grossing movies of all time. It would be simple if it were to include just the title, but I need to create the listview such that it has multiple lines. The structure being, the title is oriented left, the gross earnings aligned right and the date released is located on a second row.
The important tidbit is that I need to use string arrays declared at the strings.xml. I have already declared all of them, however my problem is that I am stuck on how to make the Java portion. Here is what I have come up so far.
package com.android.rondrich;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class Lab5_082588part2 extends ListActivity {
public static final String KEY = "KEY";
public static final String RETURN = "RETURN";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] titleList = getResources().getStringArray(R.array.title_array);
String[] grossList = getResources().getStringArray(R.array.gross_array);
setListAdapter(new ArrayAdapter<String>(this,
R.layout.lab5_082588part2, grossList)); //not sure if correct to have 2 setListAdapters
setListAdapter(new ArrayAdapter<String>(this,
R.layout.lab5_082588part2, titleList));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = getIntent();
String title = ((TextView) view).getText().toString();
intent.putExtra(Lab5_082588part2.RETURN, title);
setResult(RESULT_OK, intent);
finish();
}
});
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
finish();
}
}
Some of the snippets I have researched are using this kind of approach (sample code)
private ArrayList<SearchResults> GetSearchResults(){
ArrayList<SearchResults> results = new ArrayList<SearchResults>();
SearchResults sr = new SearchResults();
sr.setName("Justin Schultz");
sr.setCityState("San Francisco, CA");
sr.setPhone("415-555-1234");
results.add(sr);
However this method will prove very tedious for long lists. The question is that:
How do I incorporate using string arrays declared in strings.xml to have multi-line listview without resorting to hardcoding it like above?