I have a ListView that gets TutorialTitels from the string file like so
public class tutorialActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial);
registerClickCallBack();
ListView listView = (ListView) findViewById(R.id.tutorialList);
String tutorialTitle1 = getResources().getString(R.string.tutorial1_title);
String tutorialTitle2 = getResources().getString(R.string.tutorial2_title);
String tutorialTitle3 = getResources().getString(R.string.tutorial3_title);
String tutorialTitle4 = getResources().getString(R.string.tutorial4_title);
String tutorialTitle5 = getResources().getString(R.string.tutorial5_title);
String tutorialTitle6 = getResources().getString(R.string.tutorial6_title);
String tutorialTitle7 = getResources().getString(R.string.tutorial7_title);
String tutorialTitle8 = getResources().getString(R.string.tutorial8_title);
String tutorialTitle9 = getResources().getString(R.string.tutorial9_title);
String tutorialTitle10 = getResources().getString(R.string.tutorial10_title);
String tutorialTitle11 = getResources().getString(R.string.tutorial11_title);
String tutorialTitle12 = getResources().getString(R.string.tutorial12_title);
String tutorialTitle13 = getResources().getString(R.string.tutorial13_title);
String tutorialTitle14 = getResources().getString(R.string.tutorial14_title);
String[] values = new String[] { tutorialTitle1, tutorialTitle2, tutorialTitle3, tutorialTitle4, tutorialTitle5, tutorialTitle6, tutorialTitle7, tutorialTitle8, tutorialTitle9, tutorialTitle10, tutorialTitle11, tutorialTitle12, tutorialTitle13, tutorialTitle14};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, values);
listView.setAdapter(adapter);
}
private void registerClickCallBack() {
ListView list = (ListView) findViewById(R.id.tutorialList);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,int position, long id) {
}
});
}
}
When I click on a listViewItem then I'd like to open up an Activity that'll show the following things:
The clicked TutorialTitel
Tutorial content (This will also come from a string file, like so
String tutorialContent1 = getResources().getString(R.string.tutorial1_content);
)Tutorial example ((This will also come from a string file, like so
String tutorialExample1 = getResources().getString(R.string.tutorial1_example);
))
I already have an XML file like so
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#FFFFFF"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" >
<TextView
android:id="@+id/tutorialTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Title"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/split"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="15dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="5dp"
android:background="#38b34a"
android:orientation="horizontal" />
<TextView
android:id="@+id/tutorialContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text=""/>
<TextView
android:id="@+id/tutorialExample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:text=""/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
The question: How do I pass the data to my activity corresponding to my clicked ListviewItem
? should I do something like
if(position == 0){
//Send data through extra bundle
}
else if(position == 1){
//send data through extra bundle
}
But there should be a better way I think, but I don't know how exactly, because what if I'll getting 100 tutorials how should I manage a list long like that? Can someone point me in the correct direction and what is the best approach to do this?