Can't get last value from JSON - android

I'm trying to get all value from a JSON API, I've managed to get almost all of them, except one! As you can see, this is the JSON output from the server. (I can't change it)
{
"error":"",
"S8tf":{
"infoToken":"wCfhXe",
"deleteToken":"gzHTfGcF",
"size":122484,
"sha1":"8c4e2bbc0794d2bd4f901a36627e555c068a94e6",
"filename":"Screen_Shot_2013-07-02_at_3.52.23_PM.png"
},
"S29N":{
"infoToken":"joRm6p",
"deleteToken":"IL5STLhq",
"size":129332,
"sha1":"b4a03897121d0320b82059c36f7a10a8ef4c113d",
"filename":"Stockholmsyndromet.docx"
}
}
As you can see, each string/"array" begins with a "fileId" this is randomly generated from the server. I'm using the code below, I can see all values like: filename, size, sh1 etc. But I can't seem to figure out how to get the "fileId". The fileId is (in this json) S8tf and S29N
My code:
public class FilesActivity extends SherlockActivity {
private static String TAG_FILENAME = "filename";
private static String TAG_SIZE = "size";
private static String TAG_ITOKEN = "infoToken";
private static String TAG_DTOKEN = "deleteToken";
private static String TAG_SHA1 = "sha1";
private ListView lv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dblist);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Files");
String response = null;
DefaultHttpClient httpClient = new DefaultHttpClient();
ResponseHandler <String> resonseHandler = new BasicResponseHandler();
HttpPost postMethod = new HttpPost("http://api.bayfiles.net/v1/account/files?session=of1903u3pj43c3can8rc33gc42");
try {
JSONObject json = new JSONObject();
json.put("filename", "error");
postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
postMethod.setHeader( "Content-Type", "application/json" );
response = httpClient.execute(postMethod,resonseHandler);
TextView txt = (TextView)findViewById(R.id.nodata);
JSONObject request = new JSONObject(response);
for (Iterator<?> keyIterator = request.keys(); keyIterator.hasNext(); ) {
String key = (String) keyIterator.next();
JSONObject object = request.optJSONObject(key);
ArrayList<fileObject> objectList = new ArrayList<fileObject>();
if (object != null) {
//Setting TAGs
TAG_FILENAME = object.getString("filename");
TAG_SIZE = object.getString("size");
TAG_ITOKEN = object.getString("infoToken");
TAG_DTOKEN = object.getString("deleteToken");
TAG_SHA1 = object.getString("sha1");
txt.setText(
TAG_FILENAME + "\n"
+ TAG_SIZE + "\n"
+ TAG_ITOKEN + "\n"
+ TAG_DTOKEN + "\n"
+ TAG_SHA1 + "\n"
+ txt.getText()
);
Log.d("log_tag", object.getString("filename"));
}
}
}
catch(Exception e)
{
e.printStackTrace();
Log.d("log_tag", "Error: " + e.toString());
}
}
}
If you didn't get it, I'm trying to catch the value from fileId aka S8tf and S29N, these are random numbers and produced by the server.
EDIT: Got it working thanks to you guys! Since I know it's irritating that the poster figure it out, and you can't, what I did is to put String fileId = key; Inside my object loop, like this:
if (object != null) {
fileObject obj = new fileObject();
obj.setFileId(key);
obj.setFileName(object.getString("filename"));
obj.setSize(object.getString("size"));
obj.setInfoToken(object.getString("infoToken"));
obj.setDeleteToken(object.getString("deleteToken"));
obj.setSha1(object.getString("sha1"));
objectList.add(obj);
Log.d("fileId", key); // Shows both of the values!
}

I just looked at the JSONObject documentation:
I feel like the getNames()-method could be what you are searching for.

If you take a look at the first part of your for loop...
JSONObject request = new JSONObject(response);
for (Iterator<?> keyIterator = request.keys(); keyIterator.hasNext(); ) {
String key = (String) keyIterator.next();
JSONObject object = request.optJSONObject(key);
You request all of the keys from the JSONObject that represents your response from the server. These keys are the values you are looking for. If you were to add a
System.out.println(key);
after the first line in your loop, you will see the values printed out ('error','S8tf', ...).

Related

Android ListView Updated by AsyncTaskLoader

I'm populating a ListView from DB. The recordset from the DB contains the Zipcode which is then transformed into City and State using google map api and then set to Listview Item.
I need to be able to set the value that is being returned from the background class in Listview. Any guidance would be very much appreciated. Thanks in advance.
for (int i = 0; i < zipcodes.getLength(); i++) {
GetCityStateInfoFromPostalCode getCityStateInfoFromPostalCode = new GetCityStateInfoFromPostalCode(getActivity(), "110001", "ta");
String mCityState = getCityStateInfoFromPostalCode.getCityState();
}
Here's Background Class that fetches the info from Google maps api
public class GetCityStateInfoFromPostalCode extends AsyncTaskLoader<String> {
private String URL;
private String mState = "";
private String mCity = "";
private Context mContext;
public String getCityState() {
return mCityState;
}
private String mCityState = "";
public GetCityStateInfoFromPostalCode(Context context, String postalCode, String language) {
super(context);
this.mContext = context;
URL = "http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:" + postalCode + "&language=" + language;
// Kick start the load process
forceLoad();
}
public String loadInBackground() {
JSONObject jsonObject;
JSONArray jsonRootArray;
JSONArray jsonAdressArray;
JSONObject addressComponentCityObject;
JSONObject addressComponentStateObject;
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(URL);
httpGet.addHeader("content-type", "application/json");
try {
HttpResponse resp = client.execute(httpGet);
String json = EntityUtils.toString(resp.getEntity(), "UTF-8");
jsonObject = new JSONObject(json);
addressComponentCityObject = new JSONObject();
addressComponentStateObject = new JSONObject();
jsonRootArray = jsonObject.getJSONArray("results");
//This points to "0"
JSONObject rootJson = jsonRootArray.getJSONObject(0);
//This points to address components
jsonAdressArray = rootJson.getJSONArray("address_components");
//This points to Object 1 (Second object of the jsonAddressArray)
addressComponentCityObject = jsonAdressArray.getJSONObject(1);
mCity = addressComponentCityObject.getString("long_name");
addressComponentStateObject = jsonAdressArray.getJSONObject(3);
mState = addressComponentStateObject.getString("long_name");
} catch (Throwable t) {
// Handle error here
t.printStackTrace();
}
this.mCityState = mCity + ", " + mState;
return mCityState;
}
}
with AsyncTask you can generate and override the methods below :
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
}
I hope this will help you :)

Retrofit with UrlEncoded Object

I could not find the correct information on this subject. The problem has already been mentioned, but there is no correct solution. No problem with request like:
#FormUrlEncoded
#POST("/guide/confirm")
Call<Model> confirm(#Field("step") String step, #Field("code") String code);
But, what is correct (!) way do encode all object, which has three or more list of other object. Parent and child object fields most converted with UrlEncoded.
// What need to do, to encode all data below?
#POST("/guide/loadinfo")
Call<Model> confirm(#Body VeryBigJsonObject object);
There was solution using TypedObject - but now is functions is deprecated, and it is not a new retrofit. I hope you can help.
JakeWharton says in some issues, that my json is not url enoded form (its too large). That is mean, that I cannot send my request to server using Retrofit? Some example json: http://www.jsoneditoronline.org/?id=661b2bae9eb520902825a58f8d44c338
I have so much troubles with sending whole class with form-urlencoded, because our server does not allow json.
I don't think it's correct way, but i dont find any better solution.
(i tried send my class by fields, but retrofit can't encode arrays in fields correctly)
After spending a lot of time, i did it like this:
public static RequestBody objectToRequestBody(Object obj)
{
String jsonString = new Gson().toJson(obj);
String reqestText = "";
try {
Object jsonObj = new JSONObject(jsonString);
reqestText = Tools.jsonToURLEncodingAux(jsonObj,"",0);
} catch (JSONException e) {
e.printStackTrace();
}
String mediaType = "application/x-www-form-urlencoded";
return RequestBody.create(okhttp3.MediaType.parse(mediaType), reqestText);
}
public static String jsonToURLEncodingAux(Object json, String prefix, int level) {
String output = "";
if (json instanceof JSONObject) {
JSONObject obj = (JSONObject)json;
Iterator<String> keys1 = obj.keys();
while (keys1.hasNext())
{
String currKey = keys1.next();
String subPrefix = "";
if(level>0) {
subPrefix = prefix + "[" + currKey + "]";
} else {
subPrefix = prefix + currKey;
}
try {
output += jsonToURLEncodingAux(obj.get(currKey), subPrefix, level + 1);
} catch (JSONException e) {
e.printStackTrace();
}
}
} else if (json instanceof JSONArray) {
JSONArray jsonArr = (JSONArray) json;
int arrLen = jsonArr.length();
for (int i = 0; i < arrLen; i++) {
String subPrefix = prefix + "[" + i + "]";
Object child = null;
try {
child = jsonArr.get(i);
output += jsonToURLEncodingAux(child, subPrefix, level + 1);
} catch (JSONException e) {
e.printStackTrace();
}
}
} else {
output = prefix + "=" + json.toString() + "&";
}
return output;
}
interface:
#Headers("Cache-Control: max-age=259200")
#POST("api/route/report/")
Observable<ReportResponsePOJO> sendReport(
#Header("Content-Type") String content_type,
#Body RequestBody report
);
and send it like this
Observable<ReportResponsePOJO> myResponsePOJOObservable = apiInterface
.sendReport(
"application/x-www-form-urlencoded",
objectToRequestBody(report))
.subscribeOn(Schedulers.io());
I hope it will work, at least for me.

AsyncTask to refresh text on UI Components [duplicate]

This question already has answers here:
Only the original thread that created a view hierarchy can touch its views ERROR
(2 answers)
Closed 8 years ago.
I have an AsyncTask class inside my main activity. This class parses a JSON Object and then it sets the texts on some UI Components like TextViews, EditTexts etc. The problem is that when it sets the text on the first TextView then it stops. It will not give an error but the "Only the original thread that created a view hierarchy can touch its views" exception which actually means that you cannot affect any UI components through the AsynTask. I read that this could be done through a Runnable thread but i am not familiar how this can be done in my code. Any suggestions will be more than welcomed!!Thank you all!!
public class PostDataAsyncTask extends AsyncTask<String, String, String> {
protected void onPreExecute() {
super.onPreExecute();
// do stuff before posting data
}
#Override
protected String doInBackground(String... params) {
String postResponse = "";
TextView txt_class = (TextView) findViewById(R.id.txt_class);
TextView v_points = (TextView) findViewById(R.id.txt_points);
//EditText name = (EditText) findViewById(R.id.fname);
try {
// url where the data will be posted
String postReceiverUrl = "http://server.com/Json/consumer.php";
Log.v(TAG, "postURL: " + postReceiverUrl);
// HttpClient
HttpClient httpClient = new DefaultHttpClient();
// post header
HttpPost httpPost = new HttpPost(postReceiverUrl);
// add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("ConsumerID", "52"));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// execute HTTP post request
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
// Convert response to String
//String result = EntityUtils.toString(response.getEntity());
// TEST
postResponse = EntityUtils.toString(resEntity).trim();
// CONVERT RESPONSE STRING TO JSON Object
JSONObject json = new JSONObject(postResponse);
// Get the JSONArray "Consumer"
JSONArray ja = json.getJSONArray("Consumer");
//List<String> detailsList = new ArrayList<String>();
// Creating the array that will hold the json items
String[] info = new String[ja.length()];
// Loop through all fields
for (int i = 0; i < ja.length(); i++) {
JSONObject c = ja.getJSONObject(i);
// Storing each json item in variable
String id = c.getString("userid");
String fname = c.getString("userfullname");
String tel1 = c.getString("tel1");
String email = c.getString("email");
String address = c.getString("address");
String county = c.getString("county");
String country = c.getString("country");
String rpoints = c.getString("RedeemPoints");
String level = c.getString("Level");
Log.v(TAG, "User ID: " + id + "\n"+ "Username: "+ fname + "\n"+ "Redeem points: "+rpoints + "\n"+ "Level: "+level);
txt_class.setText("Domotel "+ level+" Member");
v_points.setText("TestTestTest");
}
//Log.v(TAG, "Testing response: " + postResponse);
} catch (NullPointerException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return postResponse;
}
You have to update your UI in the onPostExecute of your AsyncTask.

For each key, show value - Android

Im making an app for a site, and i need some help making an for statement. I parse the JSON from the API (Server) and catch it, this is working, however i want it to show in a ListView, i've made my adapter and all that, which is working. Now when i launch the app only one line in the listview shows. So i have no idea on how to get all the values into the listview.
My Activity:
public class FilesActivity extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dblist);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Files");
String response = null;
DefaultHttpClient httpClient = new DefaultHttpClient();
ResponseHandler <String> resonseHandler = new BasicResponseHandler();
HttpPost postMethod = new HttpPost("http://api.bayfiles.net/v1/account/files?session=<SessionId>");
try {
JSONObject json = new JSONObject();
postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
postMethod.setHeader( "Content-Type", "application/json" );
response = httpClient.execute(postMethod,resonseHandler);
JSONObject request = new JSONObject(response);
for (Iterator<?> keyIterator = request.keys(); keyIterator.hasNext(); ) {
String key = (String) keyIterator.next();
JSONObject object = request.optJSONObject(key);
ArrayList<fileObject> objectList = new ArrayList<fileObject>();
//ArrayList<fileObject> results = new ArrayList<fileObject>();
if (object != null) {
fileObject obj = new fileObject();
obj.setFileId(key);
obj.setFileName(object.getString("filename"));
obj.setSize(object.getString("size"));
obj.setInfoToken(object.getString("infoToken"));
obj.setDeleteToken(object.getString("deleteToken"));
obj.setSha1(object.getString("sha1"));
objectList.add(obj);
Log.d("log_tag", object.getString("filename"));
}
final ListView lv1 = (ListView) findViewById(R.id.listobjects);
lv1.setAdapter(new MyCustomBaseAdapter(this, objectList));
lv1.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
fileObject fullObject = (fileObject)o;
Toast.makeText(FilesActivity.this, "You have chosen: " + " " + fullObject.getFileName(), Toast.LENGTH_LONG).show();
}
});
}
}
catch(Exception e)
{
e.printStackTrace();
Log.d("log_tag", "Error: " + e.toString());
}
}
}
And the adapter and fileObject are just standard, how can i make my listview show all the values?
You are creating a new ArrayListenter code here and a new MyCustomBaseAdapter in every loop iteration. Move that outside of your loop and it will show all the items.
See this: Populating a ListView using an ArrayList?
You're re-creating the arraylist every cycle through the loop. It's only ever going to have one item in it. Just create the ArrayList prior to the for-loop, and populate it inside the loop. Then after you've done that add the whole arraylist to the listview. No need to do it every single cycle. Should look like:
ArrayList<fileObject> objectList = new ArrayList<fileObject>();
for (Iterator<?> keyIterator = request.keys(); keyIterator.hasNext(); ) {
String key = (String) keyIterator.next();
JSONObject object = request.optJSONObject(key);
//ArrayList<fileObject> results = new ArrayList<fileObject>();
if (object != null) {
fileObject obj = new fileObject();
obj.setFileId(key);
obj.setFileName(object.getString("filename"));
obj.setSize(object.getString("size"));
obj.setInfoToken(object.getString("infoToken"));
obj.setDeleteToken(object.getString("deleteToken"));
obj.setSha1(object.getString("sha1"));
objectList.add(obj);
Log.d("log_tag", object.getString("filename"));
}
}//end the for-loop right here. No need to do that other stuff over and over.

How to download a JSON Object array from URL, and Store for Android App?

I'm trying to integrate an API into an android application I am writing, but am having a nightmare trying to get the JSON array. The API has a URL that returns a an JSON array, but having never used JSON before I have no idea how this works, or how to do it.
I've looked and found tons, and tons of examples, but nothing to explain why/how it is done. Any help understanding this would be greatly appreciated.
This is what I've ended up with, again with no understanding of JSON, it was a shot in the dark on my part (using examples/tutorials as a guide)...but it doesn't work :(
import org.json.*;
//Connect to URL
URL url = new URL("URL WOULD BE HERE");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
//Get Data from URL Link
int ok = connection.getResponseCode();
if (ok == 200) {
String line = null;
BufferedReader buffer = new BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
StringBuilder sb = new StringBuilder();
while ((line = buffer.readLine()) != null)
sb.append(line + '\n');
//FROM HERE ON I'm Kinda Lost & Guessed
JSONObject obj = (JSONObject) JSONValue.parse(sb.toString()); //ERROR HERE:complains it dosn't know what JSONValue is
JSONArray array = (JSONArray)obj.get("response");
for (int i=0; i < array.size(); i++) {
JSONObject list = (JSONObject) ((JSONObject)array.get(i)).get("list");
System.out.println(list.get("name")); //Used to debug
}
}
UPDATE/SOLUTION:
So, it turns out that there was nothing wrong w/t the code. I was missusing what I thought it returns. I thought it was a JSONObject array. In actuality it was a JSONObjects wrapped in an array, wrapped in a JSONObject.
For those interested/ having similar issues, this is what I ended up with. I broke it into two methods. First connect/download, then:
private String[] buildArrayList(String Json, String Find) {
String ret[] = null;
try {
JSONObject jObject = new JSONObject(Json);
JSONArray jArray = jObject.getJSONArray("response");
ret = new String[jArray.length()];
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
String var = json_data.getString(Find);
ret[i] = var;
}
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
1) use webservice to download your required Json string
2) convert it to your desired object using Google Gson
Gson gson = new Gson();
MyClass C1 = gson.fromJson(strJson, MyClass.class);
Here you used JSONValue.parse() that is invalid.
Insted of that Line write this code:
JSONObject obj = new JSONObject(<String Value>);
Ok my friend, i solved the same problem in my app with the next code:
1.- Class to handle the Http request:
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static JSONObject jObj1 = null;
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
//Log.e("JSONObject(JSONParser1):", json);
} catch (Exception e) {
Log.e("Buffer Error json1" +
"", "Error converting result json1:" + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
jObj1 = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser1:", "Error parsing data json1:" + e.toString());
}
// return JSON String
return jObj;
}
}
Later, a class to handle the json info (Arrays, Objects, String, etc...)
public class ListViewer extends ListActivity{
TextView UserName1;
TextView LastName1;
// url to make request
private static String url = "http://your.com/url";
// JSON Node names
public static final String TAG_COURSES = "Courses"; //JSONArray
//public static final String TAG_USER = "Users"; //JSONArray -unused here.
//Tags from JSon log.aspx All Data Courses.
public static final String TAG_COURSEID = "CourseId"; //Object from Courses
public static final String TAG_TITLE = "title";
public static final String TAG_INSTRUCTOR = "instructor";
public static final String TAG_LENGTH = "length";
public static final String TAG_RATING = "Rating"; //Object from Courses
public static final String TAG_SUBJECT = "subject";
public static final String TAG_DESCRIPTION = "description";
public static final String TAG_STATUS = "Status"; //Object from Courses
public static final String TAG_FIRSTNAME = "FirstName"; //Object from User
public static final String TAG_LASTNAME = "LastName"; //Object from User
// contacts JSONArray
JSONArray Courses = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_main);
// Hashmap for ListView
final ArrayList<HashMap<String, String>> coursesList = new ArrayList<HashMap<String, String>>();
// Creating JSON Parser instance (json2)
JSONParser2 jParser2 = new JSONParser2();
// getting JSON string from URL json2
final JSONObject json2 = jParser2.getJSONFromUrl(url);
try {
// Getting Array of Contacts
Courses = json2.getJSONArray(TAG_COURSES);
// looping through All Courses
for(int i = 0; i < Courses.length(); i++){
JSONObject courses1 = Courses.getJSONObject(i);
// Storing each json item in variable
String courseID = courses1.getString(TAG_COURSEID);
//String status = courses1.getString(TAG_STATUS);
String Title = courses1.getString(TAG_TITLE);
String instructor = courses1.getString(TAG_INSTRUCTOR);
String length = courses1.getString(TAG_LENGTH);
String rating = courses1.getString(TAG_RATING);
String subject = courses1.getString(TAG_SUBJECT);
String description = courses1.getString(TAG_DESCRIPTION);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_COURSEID,courseID);
map.put(TAG_TITLE, Title);
map.put(TAG_INSTRUCTOR, instructor);
map.put(TAG_LENGTH, length);
map.put(TAG_RATING, rating);
map.put(TAG_SUBJECT, subject);
map.put(TAG_DESCRIPTION, description);
//adding HashList to ArrayList
coursesList.add(map);
}} //for Courses
catch (JSONException e) {
e.printStackTrace();
}
//Updating parsed JSON data into ListView
ListAdapter adapter = new SimpleAdapter(this, coursesList,
R.layout.list_courses,
new String[] { TAG_COURSEID, TAG_TITLE, TAG_INSTRUCTOR, TAG_LENGTH, TAG_RATING, TAG_SUBJECT, TAG_DESCRIPTION }, new int[] {
R.id.txt_courseid, R.id.txt_title, R.id.txt_instructor, R.id.txt_length, R.id.txt_rating, R.id.txt_topic, R.id.txt_description });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
//#Override --------check this override for onClick event---------
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String courseID = ((TextView) view.findViewById(R.id.txt_courseid)).getText().toString();
String Title = ((TextView) view.findViewById(R.id.txt_title)).getText().toString();
String instructor = ((TextView) view.findViewById(R.id.txt_instructor)).getText().toString();
String length = ((TextView) view.findViewById(R.id.txt_length)).getText().toString();
String rating = ((TextView) view.findViewById(R.id.txt_rating)).getText().toString();//Check place in layout
String subject = ((TextView) view.findViewById(R.id.txt_topic)).getText().toString();// <- HERE
String description = ((TextView) view.findViewById(R.id.txt_description)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleListItem.class);
in.putExtra(TAG_COURSEID, courseID);
in.putExtra(TAG_TITLE, Title);
in.putExtra(TAG_INSTRUCTOR, instructor);
in.putExtra(TAG_LENGTH, length);
in.putExtra(TAG_RATING, rating);
in.putExtra(TAG_SUBJECT, subject);
in.putExtra(TAG_DESCRIPTION, description);
startActivity(in);
}
});//lv.SetOnclickListener
}//onCreate
}// Activity
in this case, i'll get the Arrays, objects... Hope this give you ideas...

Categories

Resources