Parsing item selected from 1 activity to another activity

Put your problem here if it does not fit any of the other categories.

Parsing item selected from 1 activity to another activity

Postby jerrym » Thu Apr 30, 2009 4:11 am

firstly, to plusminus well done and thanks for the time & effort on this site.

hopefully someone can help me.

i'm trying to parse an item selected from contacts in ActivityB to an EditText in ActivityA. i read plusminus' examples in sub activities and used his concepts and techniques, BUT still not able to parse this info to the EditText control/view. i do not receive any errors, hopefully someone can help me out.

my code in the ContactList Activity:
===
import org.hsc.sip.ua.R;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.view.View;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class smsContactlist extends ListActivity {
private ListAdapter mAdapter;
protected final int SUCCESS_RETURN_CODE = 1;
private static final int PICK_CONTACT = 0;
protected static final int SUB_ACTIVITY_REQUEST_CODE = 1337;
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Cursor c = getContentResolver().query(People.CONTENT_URI,null,null,null,null);
startManagingCursor(c);

String[] columns = new String [] {People.NAME};
int [] names = new int[] {R.id.row_entry};

mAdapter = new SimpleCursorAdapter(this,R.layout.lookupcontacts,c,columns,names);
setListAdapter(mAdapter);

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this,sms.class);
Cursor c = (Cursor) mAdapter.getItem(position);
String phoneId = c.getString(c.getColumnIndex(People.PRIMARY_PHONE_ID));
String phoneNo = c.getString(c.getColumnIndex(People.NUMBER));
i.setData(Uri.withAppendedPath(Phones.CONTENT_URI, phoneId));
i.putExtra("txtPhoneNo",c.getString(c.getColumnIndex(People.NUMBER)));


startActivityForResult(i, SUB_ACTIVITY_REQUEST_CODE);

}

}

===

my code in the main page containing the EditText control/view:
===
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class sms extends Activity
{
Button btnSendSMS;
EditText txtPhoneNo;
EditText txtMessage;
protected static final int SUB_ACTIVITY_REQUEST_CODE = 1337;
private static final int PICK_CONTACT = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.sms);

btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
txtMessage = (EditText) findViewById(R.id.txtMessage);
//code for searching contacts for button search contacts
Button btnSearchContacts = (Button)findViewById(R.id.btnSearchContacts);
//==== on click listener for button
btnSearchContacts.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(sms.this,smsContactlist.class);
sms.this.startActivity(i);
//startActivityForResult(i, SUB_ACTIVITY_REQUEST_CODE);
//startActivityForResult(new Intent(Intent.ACTION_PICK),PICK_CONTACT);
}
});
//=== end on click listener for button

} //closing tag for OnCreate

//start code for on activity result
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == SUB_ACTIVITY_REQUEST_CODE){

Bundle b = this.getIntent().getExtras();
String s = b.getString("txtPhoneNo");
// Find the EditText defined in the subactivity.xml
((EditText)findViewById(R.id.txtPhoneNo)).setText(s);

}
}

//end code on activity result
jerrym
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Apr 30, 2009 3:58 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests