krishnaveni
Well-Known Member
Hi.,
I have pass data from one activity to next activity using bundle in my android application.
This is my MainActivity.java file code:
[HIGH]
public class MainActivity extends Activity {
static final String URL = "http://192.168.1.168/examplefeed.xml";
private static final int Tech = 0;
private static final int Sport =1;
static String KEY_CATEGORY = "Category";
static final String KEY_TITLE = "Categoryname";
ListView lview3;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_CATEGORY);
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String> ();
Element e = (Element) nl.item(i);
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
songsList.add(map);
}
lview3 = (ListView) findViewById(R.id.listView1);
adapter = new LazyAdapter(this, songsList);
lview3.setAdapter(adapter);
lview3.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//HashMap<String, String> map = songsList.get(position);
switch (position)
{
case Tech:
Intent tech = new Intent(MainActivity.this, SubCate.class);
tech.putExtra(KEY_TITLE, "Books");
startActivity(tech);
break;
case Sport:
Intent sport = new Intent(MainActivity.this, SubCate.class);
sport.putExtra(KEY_TITLE, "CD-DVD-Video");
startActivity(sport);
break;
default:
break;
}
}
[/HIGH]
The below code is my 2nd activity code(SubCate.java):
[HIGH]
public class SubCate extends Activity {
static final String URL = "http://192.168.1.168/examplefeed.xml";
private static final int Tech = 0;
private static final int Sport =1;
static String KEY_CATEGORY = "SubCategory";
static final String KEY_SUBCATE = "subcategoryname";
static final String KEY_TITLE = "Categoryname";
ListView lview3;
ListViewCustomAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
Bundle bdl = getIntent().getExtras();
KEY_CATEGORY = bdl.getString(KEY_TITLE);
// String key = getIntent().getStringExtra(KEY_TITLE);
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_CATEGORY);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_SUBCATE, parser.getValue(e, KEY_SUBCATE));
songsList.add(map);
}
lview3 = (ListView) findViewById(R.id.listView1);
adapter = new ListViewCustomAdapter(this, songsList);
lview3.setAdapter(adapter);
lview3.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> map = songsList.get(position);
}
});
[/HIGH]
My data have values. But i have to run the app means am getting empty screen.what am doing wrong here.please help me.
This is my AndroidManifest.xml file:
[HIGH]
This is my AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SubCate"
android:label="@string/app_name" />
</application>
[/HIGH]
This is my XML feed:
[HIGH]
<Feed>
<category>
<Category>
<Categoryname>Books</Categoryname>
<SubCategory>
<subcategoryname>Internet</subcategoryname>
</SubCategory>
<SubCategory>
<subcategoryname>Software</subcategoryname>
</SubCategory>
</Category>
<Category>
<Categoryname>CD-DVD-Video</Categoryname>
<SubCategory>
<subcategoryname>CD</subcategoryname>
</SubCategory>
<SubCategory>
<subcategoryname>DVD</subcategoryname>
</SubCategory>
</Category>
</category>
</Feed>
[/HIGH]
This is my expectation output like:
Books
CD-DVD-Video
I have to click Books means its go to next activity and have to display that books subcategory only.(i.e)i have to click Book category means i have to display Internet and software only.
i have to click CD-DVD-Video means its go to next activity and have to display that CD-DVd-Video subcategories only.(i.e)i have to click CD-DVD-Video category means i have to display CD,DVD only.
This is my current output:
But i have to run the app means am getting books and cd-dvd-video on first activity.i have to click any category means blank screen is displayed.please help me.what error is occurred here.
In these 2nd activity(SubCate.java) file i have removed below line
[HIGH]Bundle bdl = getIntent().getExtras();
KEY_CATEGORY = bdl.getString(KEY_TITLE);[/HIGH]
after i have to run the app means i have getting Books CD-DVD-Video category on first page.after that i have to click any category means i have displayed all subcategories on each category list.
FOR EG:
i have to click Book category means i have to display Internet and software only.but here displayed internet,software,cd,dvd.
and also i have to click CD-DVD-Video category means i have to display CD,DVD only.But here also displayed 4 subcategories.what is wrongly done here.please help me.
I have pass data from one activity to next activity using bundle in my android application.
This is my MainActivity.java file code:
[HIGH]
public class MainActivity extends Activity {
static final String URL = "http://192.168.1.168/examplefeed.xml";
private static final int Tech = 0;
private static final int Sport =1;
static String KEY_CATEGORY = "Category";
static final String KEY_TITLE = "Categoryname";
ListView lview3;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_CATEGORY);
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String> ();
Element e = (Element) nl.item(i);
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
songsList.add(map);
}
lview3 = (ListView) findViewById(R.id.listView1);
adapter = new LazyAdapter(this, songsList);
lview3.setAdapter(adapter);
lview3.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//HashMap<String, String> map = songsList.get(position);
switch (position)
{
case Tech:
Intent tech = new Intent(MainActivity.this, SubCate.class);
tech.putExtra(KEY_TITLE, "Books");
startActivity(tech);
break;
case Sport:
Intent sport = new Intent(MainActivity.this, SubCate.class);
sport.putExtra(KEY_TITLE, "CD-DVD-Video");
startActivity(sport);
break;
default:
break;
}
}
[/HIGH]
The below code is my 2nd activity code(SubCate.java):
[HIGH]
public class SubCate extends Activity {
static final String URL = "http://192.168.1.168/examplefeed.xml";
private static final int Tech = 0;
private static final int Sport =1;
static String KEY_CATEGORY = "SubCategory";
static final String KEY_SUBCATE = "subcategoryname";
static final String KEY_TITLE = "Categoryname";
ListView lview3;
ListViewCustomAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
Bundle bdl = getIntent().getExtras();
KEY_CATEGORY = bdl.getString(KEY_TITLE);
// String key = getIntent().getStringExtra(KEY_TITLE);
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_CATEGORY);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_SUBCATE, parser.getValue(e, KEY_SUBCATE));
songsList.add(map);
}
lview3 = (ListView) findViewById(R.id.listView1);
adapter = new ListViewCustomAdapter(this, songsList);
lview3.setAdapter(adapter);
lview3.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> map = songsList.get(position);
}
});
[/HIGH]
My data have values. But i have to run the app means am getting empty screen.what am doing wrong here.please help me.
This is my AndroidManifest.xml file:
[HIGH]
This is my AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SubCate"
android:label="@string/app_name" />
</application>
[/HIGH]
This is my XML feed:
[HIGH]
<Feed>
<category>
<Category>
<Categoryname>Books</Categoryname>
<SubCategory>
<subcategoryname>Internet</subcategoryname>
</SubCategory>
<SubCategory>
<subcategoryname>Software</subcategoryname>
</SubCategory>
</Category>
<Category>
<Categoryname>CD-DVD-Video</Categoryname>
<SubCategory>
<subcategoryname>CD</subcategoryname>
</SubCategory>
<SubCategory>
<subcategoryname>DVD</subcategoryname>
</SubCategory>
</Category>
</category>
</Feed>
[/HIGH]
This is my expectation output like:
Books
CD-DVD-Video
I have to click Books means its go to next activity and have to display that books subcategory only.(i.e)i have to click Book category means i have to display Internet and software only.
i have to click CD-DVD-Video means its go to next activity and have to display that CD-DVd-Video subcategories only.(i.e)i have to click CD-DVD-Video category means i have to display CD,DVD only.
This is my current output:
But i have to run the app means am getting books and cd-dvd-video on first activity.i have to click any category means blank screen is displayed.please help me.what error is occurred here.
In these 2nd activity(SubCate.java) file i have removed below line
[HIGH]Bundle bdl = getIntent().getExtras();
KEY_CATEGORY = bdl.getString(KEY_TITLE);[/HIGH]
after i have to run the app means i have getting Books CD-DVD-Video category on first page.after that i have to click any category means i have displayed all subcategories on each category list.
FOR EG:
i have to click Book category means i have to display Internet and software only.but here displayed internet,software,cd,dvd.
and also i have to click CD-DVD-Video category means i have to display CD,DVD only.But here also displayed 4 subcategories.what is wrongly done here.please help me.