i have fragment with listview
myfragment :
public class LightFragment extends Fragment {
String[] name;
String[] type;
String[] swim;
int[] flag;
ListView list;
ListViewAdapter adapter;
public LightFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_light, container, false);
name = getResources().getStringArray(R.array.sport);
type = new String[] { "China", "India", "United States",
"Indonesia", "Brazil" };
swim = new String[] { "1,354,040,000", "1,210,193,422",
"315,761,000", "237,641,326", "193,946,886" };
flag = new int[] { R.drawable.light11,
R.drawable.light12,
R.drawable.light21,
R.drawable.light22,
R.drawable.light23,
R.drawable.light24,
R.drawable.light25,
R.drawable.light26,
R.drawable.light27 };
// Locate the ListView in fragmenttab1.xml
list = (ListView) rootView.findViewById(R.id.listview);
// Pass results to ListViewAdapter Class
adapter = new ListViewAdapter(getActivity(), name, type, swim,
flag);
// Binds the Adapter to the ListView
list.setAdapter(adapter);
// Capture clicks on ListView items
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Send single item click data to SingleItemView Class
Intent i = new Intent(getActivity(), SingleItemView.class);
// Pass all data rank
i.putExtra("rank", name);
// Pass all data country
i.putExtra("country", type);
// Pass all data population
i.putExtra("population", swim);
// Pass all data flag
i.putExtra("flag", flag);
// Pass a single position
i.putExtra("position", position);
// Open SingleItemView.java Activity
startActivity(i);
}
});
return rootView;
}
}
Listviewadapter :
public class ListViewAdapter extends BaseAdapter {
// Declare Variables
Context context;
String[] rank;
String[] country;
String[] population;
int[] flag;
LayoutInflater inflater;
public ListViewAdapter(Context context, String[] rank, String[] country,
String[] population, int[] flag) {
this.context = context;
this.rank = rank;
this.country = country;
this.population = population;
this.flag = flag;
}
public int getCount() {
return rank.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView txtrank;
TextView txtcountry;
TextView txtpopulation;
ImageView imgflag;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.listview_item, parent, false);
// Locate the TextViews in listview_item.xml
txtrank = (TextView) itemView.findViewById(R.id.name);
txtcountry = (TextView) itemView.findViewById(R.id.type);
txtpopulation = (TextView) itemView.findViewById(R.id.swim);
// Locate the ImageView in listview_item.xml
imgflag = (ImageView) itemView.findViewById(R.id.flag);
// Capture position and set to the TextViews
txtrank.setText(rank[position]);
txtcountry.setText(country[position]);
txtpopulation.setText(population[position]);
// Capture position and set to the ImageView
imgflag.setImageResource(flag[position]);
return itemView;
}
}
mysingleviewitem :
public class SingleItemView extends Activity {
TextView txtname;
TextView txttype;
TextView txtswim;
TextView txtfunny;
TextView txtwalking;
TextView txtangry;
TextView txtsad;
ImageView imgflag;
String[] name;
String[] type;
String[] swim;
String[] funny;
String[] walking;
String[] angry;
String[] sad;
int[] flag;
int position;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.singleitemview);
Intent i = getIntent();
// Get a single position
position = i.getExtras().getInt("position");
// Get the list of rank
name = i.getStringArrayExtra("rank");
// Get the list of country
type = i.getStringArrayExtra("country");
// Get the list of population
swim = i.getStringArrayExtra("population");
funny = i.getStringArrayExtra("rank");
// Get the list of country
walking = i.getStringArrayExtra("country");
// Get the list of population
angry = i.getStringArrayExtra("population");
sad = i.getStringArrayExtra("rank");
// Get the list of flag
flag = i.getIntArrayExtra("flag");
// Locate the TextViews in singleitemview.xml
txtname = (TextView) findViewById(R.id.name);
txttype = (TextView) findViewById(R.id.type);
txtswim = (TextView) findViewById(R.id.swim);
txtfunny = (TextView) findViewById(R.id.funny);
txtwalking = (TextView) findViewById(R.id.walking);
txtangry = (TextView) findViewById(R.id.angry);
txtsad = (TextView) findViewById(R.id.sad);
// Locate the ImageView in singleitemview.xml
imgflag = (ImageView) findViewById(R.id.flag);
// Load the text into the TextViews followed by the position
txtname.setText(name[position]);
txttype.setText(type[position]);
txtswim.setText(swim[position]);
txtfunny.setText(funny[position]);
txtwalking.setText(walking[position]);
txtangry.setText(angry[position]);
txtsad.setText(sad[position]);
// Load the image into the ImageView followed by the position
imgflag.setImageResource(flag[position]);
}
}
myarray :
<string-array name="sport">
<item >Lari</item>
<item >Bola</item>
<item >Balap</item>
<item >tinju</item>
<item >renang</item>
</string-array>
<string-array name="Lari">
<item >100 meter</item>
<item >mulai</item>
<item >finish</item>
<item >piala</item>
</string-array>
detail: ListViewItem with the title of the string array "sport" and managed according to the layout of the array string.
and when clicked will open singleviewitem listview but I want the words that appear taken from <string-array name = "Lari">
and so on according listview of <string-array name = "sport">
so for example I click listview with Running title will be out is
<item >100 meter</item>
<item >mulai</item>
<item >finish</item>
<item >piala</item>
Please help,
sorry, my english is bad
nb: I've tried getstringarray the position but only raises the string according to the position of the clicked listview