Sunday, April 14, 2013

[android help] success in logcat but empty screen


I currently have this one problem. and because of this, i cant do any other because i have to refer to this page. I would be grateful if anyone could point out the mistake i made.


I wanted to view the details of a specific product where the button from previous page (list) will pass the ID parameter to the page (details). there is no error in the Java code or PHP code. i'm sure about this because the Logcat shows the results accordingly (as i added the log thing everywhere). but the page is empty in the emulator. i don't understand why this happens as the layout is designed same as other pages as well. In case you need the code, its as below:


Java code: list.java



ListView lv = getListView();

lv.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView parent, View view,
int position, long id) {

String pid = ((TextView) view.findViewById(R.id.pid)).getText()
.toString();

// Starting new intent
Intent in = new Intent(getApplicationContext(),
details.class);
// sending pid to next activity
in.putExtra(TAG_PID, pid);

// starting new activity and expecting some response back
startActivity(in);
}
});


Java code: details.java



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_details);


Intent i = getIntent();

// getting product id (pid) from intent
pid = i.getStringExtra(TAG_PID);

Log.d("pid is:",pid);

new GetProductDetails().execute();

}

class GetProductDetails extends AsyncTask {


@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Details.this);
pDialog.setMessage("Loading. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}

protected String doInBackground(String... params) {


runOnUiThread(new Runnable() {
public void run() {

int success;
try {
List params = new ArrayList();
params.add(new BasicNameValuePair("pid", pid));

JSONObject json = jParser.makeHttpRequest(url_product_details, "GET", params);


Log.d("Single Product Details", json.toString());


success = json.getInt(TAG_SUCCESS);
if (success == 1) {

JSONArray productObj = json.getJSONArray(TAG_BOOK);
JSONObject product = productObj.getJSONObject(0);
title = product.getString(TAG_TITLE);
description=product.getString(TAG_CATEGORY);


Layout: details.xml



android:layout_width="match_parent"
android:layout_height="match_parent" >

android:layout_marginTop="70dp"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"/>



thank you so much!



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...