我需要创建一个登录应用程序,我必须在成功登录身份验证和用户名列表视图的 onItemClick 时仅在列表视图中显示用户名,我必须在另一个活动的文本视图中显示用户详细信息,如姓名、电子邮件和地址。所有用户详细信息都应从 Xml 文件中解析。
基本上,我有三个活动,即 1. Login.java 2. Users.java 3. UserDetails.java
但是,我已将用户名从(Users.java)列表视图发送到 userdetails(在 Textview 上)。现在,我需要向 (UserDetails) 活动发送电子邮件、地址。问题是电子邮件和地址不在(Users.java)列表视图中,我只显示用户名。
任何帮助将不胜感激。谢谢 !
这是我的Users.java
public class Users extends Activity {
ListView myList ;
List<String> fillUsers;
List<String> fillemail;
List<String> fillphone;
List<String> fillplace;
List<String> titles;
List<String> link1;
//private List<Map<String, Object>> data;
private ListView listView = null;
private List<com.example.firstapp.Message> messages;
static final String KEY_FNAME = "fname";
static final String KEY_LNAME = "lname";
static final String KEY_EMAIL = "email";
static final String KEY_PHONE = "phone";
static final String KEY_PLACE = "place";
List headlines;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);
new MyAsyncTask().execute();
}
private class MyAsyncTask extends AsyncTask<Void, Void, Void>
{
ProgressDialog mProgressDialog;
@Override
protected void onPostExecute(Void result) {
mProgressDialog.dismiss();
final ListView listView = (ListView) findViewById(R.id.listview);
final ArrayAdapter<String> listAdapter= new ArrayAdapter<String>(Users.this, android.R.layout.simple_list_item_1, fillUsers);
listView.setAdapter(listAdapter);
try{
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedFromList =(String) (listView.getItemAtPosition(position));
System.out.println("Testing 006: "+fillemail+fillphone+fillplace);
System.out.println("Testing 008: "+selectedFromList);
Intent in = new Intent(Users.this,UserDetails.class);
System.out.println("Testing 009: ");
Bundle myBundle = new Bundle(); //create a Bundle
myBundle.putString("username",selectedFromList);
myBundle.putInt("userid",1234);
System.out.println("Testing 010: ");
in.putExtras(myBundle); //PUT THE Bundle you created in the Intent
startActivityForResult(in, 0);
System.out.println("Testing 010: ");
}
});
}catch(Exception ex){
System.out.println("On item click : 0070"+ex.toString());
System.out.println("On item click : 0080"+ex.getStackTrace().toString());
}
}
@Override
protected void onPreExecute() {
mProgressDialog = ProgressDialog.show(Users.this, "", "Loading. Please wait...", true);
}
@Override
protected Void doInBackground(Void... params) {
// your network operation
loadFeed();
return (null);
}
public void loadFeed(){
try{
BaseFeedParser parser = new BaseFeedParser();
messages = parser.parse();
Log.e("check=","yes");
List<String> titles = new ArrayList<String>(messages.size());
HashMap<String, String> map = new HashMap<String, String>();
int count=0;
for (com.example.firstapp.Message msg : messages){
count++;
}
fillUsers = new ArrayList<String>(count);
fillemail = new ArrayList<String>(count);
fillphone = new ArrayList<String>(count);
fillplace = new ArrayList<String>(count);
for (com.example.firstapp.Message msg : messages){
fillUsers.add(msg.getFname()+" "+msg.getLname());
fillemail.add(msg.getEmail());
fillphone.add(msg.getPhone());
fillplace.add(msg.getPlace());
System.out.println("OOOOOOOOOOOO "+fillemail.toString());
}
return;
} catch (Throwable t){
Log.e("AndroidNews",t.getMessage(),t);
t.printStackTrace();
}
}
}
}