- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 ListView 适配器有问题,一切都通过 json 解析到 ListView 中,一切正常,但是当我单击 ListView 时,它总是向我显示 ListView 中最后解析的 json 的结果。
这是我的第一个类 Jobs:
public class Jobs extends ListActivity {
// JSON Node names
private static final String jobs = "jobs";
private static final String job = "job";
private static final String pays = "pays";
private static final String ready_at = "ready_at";
private static final String due_by = "due_by";
private static final String customer_reference = "customer_reference";
private static final String pieces = "pieces";
private static final String weight = "weight";
private static final String pickup_name = "pickup_name";
private static final String pickup_addr1 = "pickup_addr1";
private static final String pickup_city = "pickup_city";
private static final String pickup_state = "pickup_state";
private static final String pickup_zip_postal = "pickup_zip_postal";
private static final String deliver_name = "deliver_name";
private static final String deliver_addr1 = "deliver_addr1";
private static final String deliver_city = "deliver_city";
private static final String deliver_state = "deliver_state";
private static final String deliver_zip_postal = "deliver_zip_postal";
private static final String signature_required = "signature_required";
private static final String pickup_to_see = "pickup_to_see";
private static final String pickup_room = "pickup_room";
private static final String pickup_phone = "pickup_phone";
private static final String deliver_to_see = "deliver_to_see";
private static final String deliver_room = "deliver_room";
private static final String pickup_special_instr = "pickup_special_instr";
private static final String deliver_special_instr = "deliver_special_instr";
private static final String deliver_phone = "deliver_phone";
String JOB, PAYS, READY_AT, DUE_BY, CUSTOMER_REFERENCE, PIECES, WEIGHT, PICKUP_NAME, PICKUP_ADDR1, PICKUP_CITY, PICKUP_STATE,
PICKUP_ZIP_POSTAL, DELIVER_NAME, DELIVER_ADDR1, DELIVER_CITY, DELIVER_STATE, DELIVER_ZIP_POSTAL, SIGNATURE_REQUIRED,
PICKUP_TO_SEE, PICKUP_ROOM, PICKUP_PHONE, DELIVER_TO_SEE, DELIVER_ROOM, PICKUP_SPECIAL_INSTR, DELIVER_SPECIAL_INSTR,
DELIVER_PHONE;
// Strings
String username, password, firstName, lastName, lastLatitudeUpdate, dvrcheckin, dvrScheduleToWork, dvrStartTime, jobs_assigned;
int checkedin, Minute, Hour, Minutedvr, Hourdvr, status;
Vibrator vib;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jobs);
vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
new ParseJobs().execute();
TextView assigned = (TextView) findViewById(R.id.assigned);
if (jobs_assigned.matches("0")){
assigned.setText("You have no jobs assigned");
} else {
assigned.setVisibility(View.GONE);
}
// selecting single ListView item
ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long ide) {
vib.vibrate(40);
// Starting new intent
Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);
in.putExtra(pays, PAYS);
in.putExtra(job, JOB);
in.putExtra(ready_at, READY_AT);
in.putExtra(due_by, DUE_BY);
in.putExtra(customer_reference, CUSTOMER_REFERENCE);
in.putExtra(pieces, PIECES);
in.putExtra(weight, WEIGHT);
in.putExtra(pickup_name, PICKUP_NAME);
in.putExtra(pickup_addr1, PICKUP_ADDR1);
in.putExtra(pickup_city, PICKUP_CITY);
in.putExtra(pickup_state, PICKUP_STATE);
in.putExtra(pickup_zip_postal, PICKUP_ZIP_POSTAL);
in.putExtra(deliver_name, DELIVER_NAME);
in.putExtra(deliver_addr1, DELIVER_ADDR1);
in.putExtra(deliver_city, DELIVER_CITY);
in.putExtra(deliver_state, DELIVER_STATE);
in.putExtra(deliver_zip_postal, DELIVER_ZIP_POSTAL);
in.putExtra(signature_required, SIGNATURE_REQUIRED);
in.putExtra(pickup_to_see, PICKUP_TO_SEE);
in.putExtra(pickup_room, PICKUP_ROOM);
in.putExtra(pickup_phone, PICKUP_PHONE);
in.putExtra(deliver_to_see, DELIVER_TO_SEE);
in.putExtra(deliver_room, DELIVER_ROOM);
in.putExtra(pickup_special_instr, PICKUP_SPECIAL_INSTR);
in.putExtra(deliver_special_instr, DELIVER_SPECIAL_INSTR);
in.putExtra(deliver_phone, DELIVER_PHONE);
startActivity(in);
Jobs.this.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
});
}
public class ParseJobs extends AsyncTask<Void, Void, Void> {
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
// contacts JSONArray
JSONArray JOBS;
ProgressDialog VerifyDriver;
@Override
protected void onPreExecute() {
VerifyDriver = ProgressDialog.show(Jobs.this, "Getting Your Jobs", "Loading Data... Please Wait...");
WindowManager.LayoutParams lp = VerifyDriver.getWindow().getAttributes();
VerifyDriver.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
lp.dimAmount = .65f;
VerifyDriver.getWindow().setAttributes(lp);
Intent i = getIntent();
username = i.getExtras().getString("uid");
password = i.getExtras().getString("pwd");
firstName = i.getExtras().getString("firstName");
lastName = i.getExtras().getString("lastName");
lastLatitudeUpdate = i.getExtras().getString("lastLatitudeUpdate");
Minute = i.getExtras().getInt("Minute");
Hour = i.getExtras().getInt("Hour");
dvrcheckin = i.getExtras().getString("check-in");
Hourdvr = i.getExtras().getInt("Hourdvr");
Minutedvr = i.getExtras().getInt("Minutedvr");
status = i.getExtras().getInt("status");
dvrScheduleToWork = i.getExtras().getString("dvrScheduleToWork");
dvrStartTime = i.getExtras().getString("dvrStartTime");
jobs_assigned = i.getExtras().getString("jobs_assigned");
}
@Override
protected Void doInBackground(Void... params) {
// getting JSON string from URL
JSONObject json = JSONfunction.getJSONfromURL("http://www.jetdelivery.com/mobile/api/getresourcestatus/?type=json&uid=" + (username) + "&pwd=" + (password));
try {
// Getting Array of Contacts
JOBS = json.getJSONArray(jobs);
// looping through All Contacts
for (int i1 = 0; i1 < JOBS.length(); i1++) {
JSONObject c = JOBS.getJSONObject(i1);
// Storing each json item in variable
JOB = c.getString(job);
PAYS = c.getString(pays);
READY_AT = c.getString(ready_at);
DUE_BY = c.getString(due_by);
DELIVER_PHONE = c.getString(deliver_phone);
PIECES = c.getString(pieces);
WEIGHT = c.getString(weight);
PICKUP_NAME = c.getString(pickup_name);
PICKUP_ADDR1 = c.getString(pickup_addr1);
PICKUP_CITY = c.getString(pickup_city);
PICKUP_STATE = c.getString(pickup_state);
PICKUP_ZIP_POSTAL = c.getString(pickup_zip_postal);
DELIVER_NAME = c.getString(deliver_name);
DELIVER_ADDR1 = c.getString(deliver_addr1);
DELIVER_CITY = c.getString(deliver_city);
DELIVER_STATE = c.getString(deliver_state);
DELIVER_ZIP_POSTAL = c.getString(deliver_zip_postal);
SIGNATURE_REQUIRED = c.getString(signature_required);
PICKUP_TO_SEE = c.getString(pickup_to_see);
PICKUP_ROOM = c.getString(pickup_room);
PICKUP_PHONE = c.getString(pickup_phone);
DELIVER_TO_SEE = c.getString(deliver_to_see);
DELIVER_ROOM = c.getString(deliver_room);
PICKUP_SPECIAL_INSTR = c.getString(pickup_special_instr);
DELIVER_SPECIAL_INSTR = c.getString(deliver_special_instr);
CUSTOMER_REFERENCE = c.getString(customer_reference);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(job, JOB);
map.put(pays, PAYS);
map.put(ready_at, READY_AT);
// map.put(weight, mobile);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
WindowManager.LayoutParams params = getWindow().getAttributes();
Jobs.this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
params.x = 0;
params.height = 520;
params.width = 480;
params.y = 200;
params.dimAmount = .70f;
Jobs.this.getWindow().setAttributes(params);
/** Updating parsed JSON data into ListView */
ListAdapter adapter = new SimpleAdapter(Jobs.this, contactList, R.layout.list_item, new String[] { job, pays, ready_at }, new int[] { R.id.job1, R.id.pays1, R.id.ready_at1 });
setListAdapter(adapter);
VerifyDriver.dismiss();
}
}
@Override
protected void onResume() {
super.onResume();
Jobs.this.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
@Override
protected void onPause() {
super.onPause();
Jobs.this.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
@Override
public void onBackPressed() {
vib.vibrate(40);
// Send username and password strings into screen1 class
Intent i = new Intent(Jobs.this, screen1.class);
i.putExtra("uid", username);
i.putExtra("pwd", password);
i.putExtra("Minute", Minute);
i.putExtra("Hour", Hour);
i.putExtra("firstName", firstName);
i.putExtra("lastName", lastName);
i.putExtra("check-in", dvrcheckin);
i.putExtra("Hourdvr", Hourdvr);
i.putExtra("Minutedvr", Minutedvr);
i.putExtra("status", status);
i.putExtra("lastLatitudeUpdate", lastLatitudeUpdate);
i.putExtra("dvrScheduleToWork", dvrScheduleToWork);
i.putExtra("dvrStartTime", dvrStartTime);
i.putExtra("jobs_assigned", jobs_assigned);
Jobs.this.finish();
startActivity(i);
Jobs.this.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
@Override
protected void onRestart() {
super.onRestart();
Intent i = new Intent(this, AgentPortalActivity.class);
startActivity(i);
Jobs.this.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
}
这是我的第二类,当您单击 ListView 时,它只显示有关该工作的更多信息:
public class SingleMenuItemActivity extends Activity {
// JSON Node names
private static final String job = "job";
private static final String pays = "pays";
private static final String ready_at = "ready_at";
private static final String due_by = "due_by";
private static final String customer_reference = "customer_reference";
private static final String pieces = "pieces";
private static final String weight = "weight";
private static final String pickup_name = "pickup_name";
private static final String pickup_addr1 = "pickup_addr1";
private static final String pickup_city = "pickup_city";
private static final String pickup_state = "pickup_state";
private static final String pickup_zip_postal = "pickup_zip_postal";
private static final String deliver_name = "deliver_name";
private static final String deliver_addr1 = "deliver_addr1";
private static final String deliver_city = "deliver_city";
private static final String deliver_state = "deliver_state";
private static final String deliver_zip_postal = "deliver_zip_postal";
private static final String signature_required = "signature_required";
private static final String pickup_to_see = "pickup_to_see";
private static final String pickup_room = "pickup_room";
private static final String pickup_phone = "pickup_phone";
private static final String deliver_to_see = "deliver_to_see";
private static final String deliver_room = "deliver_room";
private static final String pickup_special_instr = "pickup_special_instr";
private static final String deliver_special_instr = "deliver_special_instr";
private static final String deliver_phone = "deliver_phone";
String JOB, PAYS, READY_AT, DUE_BY, CUSTOMER_REFERENCE, PIECES, WEIGHT, SIGNATURE_REQUIRED, // General Job Information
PICKUP_NAME,PICKUP_TO_SEE, PICKUP_ROOM, PICKUP_ADDR1, PICKUP_CITY, PICKUP_STATE, PICKUP_ZIP_POSTAL, PICKUP_PHONE, PICKUP_SPECIAL_INSTR, // Pickup Job Information
DELIVER_NAME, DELIVER_ADDR1, DELIVER_CITY, DELIVER_STATE, DELIVER_ZIP_POSTAL, DELIVER_TO_SEE, DELIVER_ROOM, DELIVER_SPECIAL_INSTR, DELIVER_PHONE, // Deliver Job Information
username, password, firstName, lastName, lastLatitudeUpdate, dvrcheckin, dvrScheduleToWork, dvrStartTime, jobs_assigned; // Original Strings Passed through from main Activity
int checkedin, Minute, Hour, Minutedvr, Hourdvr, status; // Integers Passed through from main Activity
Vibrator vib;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.single_menu_item_activity);
vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
Get_Intents();
////////////////////////////////////////////////////////
//////// Initializing all TextViews ////////
////////////////////////////////////////////////////////
TextView trackno = (TextView) findViewById(R.id.trackno);
TextView readyAT = (TextView) findViewById(R.id.readyAT);
TextView jobpays = (TextView) findViewById(R.id.jobpays);
TextView pcs = (TextView) findViewById(R.id.pcs);
TextView weightt = (TextView) findViewById(R.id.weightt);
TextView custref = (TextView) findViewById(R.id.custref);
TextView dueby = (TextView) findViewById(R.id.dueby);
TextView sigreq = (TextView) findViewById(R.id.sigreq);
/////////////// PickUp TextViews //////////////////////
TextView puname = (TextView) findViewById(R.id.puname);
TextView puaddress = (TextView) findViewById(R.id.puaddress);
TextView puroom = (TextView) findViewById(R.id.puroom);
TextView pusee = (TextView) findViewById(R.id.pusee);
TextView puphone = (TextView) findViewById(R.id.puphone);
TextView puinstructions = (TextView) findViewById(R.id.puinstructions);
////////////// Deliver TextViews ///////////////////
TextView delname = (TextView) findViewById(R.id.delname);
TextView deladdress = (TextView) findViewById(R.id.deladdress);
TextView delroom = (TextView) findViewById(R.id.delroom);
TextView delsee = (TextView) findViewById(R.id.delsee);
TextView delphone = (TextView) findViewById(R.id.delphone);
TextView delinstructions = (TextView) findViewById(R.id.delinstructions);
///////////// Miscellaneous TextViews /////////////////
TextView origin = (TextView) findViewById(R.id.origin);
TextView destination = (TextView) findViewById(R.id.destination);
origin.setText(Html.fromHtml("<i><u>ORIGIN</u></i> "));
destination.setText(Html.fromHtml("<i><u>DESTINATION</u></i> "));
/////////////////////////////////
// Setting String to TextViews //
/////////////////////////////////
trackno.setText(JOB);
readyAT.setText(READY_AT);
jobpays.setText(PAYS);
pcs.setText(PIECES);
weightt.setText((WEIGHT) + " Lbs");
custref.setText(CUSTOMER_REFERENCE);
dueby.setText(DUE_BY);
///////// Pickup Info ///////////
puname.setText(PICKUP_NAME);
puaddress.setText((PICKUP_ADDR1) + "\n" + (PICKUP_CITY) + " " + (PICKUP_STATE) + " " + (PICKUP_ZIP_POSTAL));
puroom.setText(PICKUP_ROOM);
pusee.setText(PICKUP_TO_SEE);
puphone.setText(PICKUP_PHONE);
puinstructions.setText(PICKUP_SPECIAL_INSTR);
///////// Deliver Info //////////
delname.setText(DELIVER_NAME);
deladdress.setText((DELIVER_ADDR1) + "\n" + (DELIVER_CITY) + " " + (DELIVER_STATE) + " " + (DELIVER_ZIP_POSTAL));
delroom.setText(DELIVER_ROOM);
delsee.setText(DELIVER_TO_SEE);
delphone.setText(DELIVER_PHONE);
delinstructions.setText(DELIVER_SPECIAL_INSTR);
//// Fixing String To Display ////
//// Yes or No Instead of Y or N ////
if (SIGNATURE_REQUIRED.matches("Y")){
sigreq.setText("Yes");
}
if (SIGNATURE_REQUIRED.matches("N")){
sigreq.setText("No");
}
Accept_Job_Button_Instructions();
Deny_Job_Button_Instructions();
}
private void Deny_Job_Button_Instructions() {
///////////////// Deny Button ///////////////////////////////
Button deny = (Button) findViewById(R.id.deny);
deny.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
vib.vibrate(40);
startActivity(new Intent(SingleMenuItemActivity.this, JobDenied.class)); //SingleMenuItemActivity.this.finish();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
});
}
private void Accept_Job_Button_Instructions() {
///////////////// Accept Button //////////////////////////////
Button accept = (Button) findViewById(R.id.accept);
accept.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
vib.vibrate(40);
}
});
}
// First Initialize upon Starting Activity //
private void Get_Intents() {
// getting intent data
Intent in = getIntent();
// Get JSON values from previous intent
PAYS = in.getStringExtra(pays);
JOB = in.getStringExtra(job);
READY_AT = in.getStringExtra(ready_at);
DUE_BY = in.getStringExtra(due_by);
CUSTOMER_REFERENCE = in.getStringExtra(customer_reference);
PIECES = in.getStringExtra(pieces);
WEIGHT = in.getStringExtra(weight);
SIGNATURE_REQUIRED = in.getStringExtra(signature_required);
// PickUp Info
PICKUP_NAME = in.getStringExtra(pickup_name);
PICKUP_ADDR1 = in.getStringExtra(pickup_addr1);
PICKUP_CITY = in.getStringExtra(pickup_city);
PICKUP_STATE = in.getStringExtra(pickup_state);
PICKUP_ZIP_POSTAL = in.getStringExtra(pickup_zip_postal);
PICKUP_TO_SEE = in.getStringExtra(pickup_to_see);
PICKUP_ROOM = in.getStringExtra(pickup_room);
PICKUP_PHONE = in.getStringExtra(pickup_phone);
PICKUP_SPECIAL_INSTR = in.getStringExtra(pickup_special_instr);
//Deliver Info
DELIVER_NAME = in.getStringExtra(deliver_name);
DELIVER_ADDR1 = in.getStringExtra(deliver_addr1);
DELIVER_CITY = in.getStringExtra(deliver_city);
DELIVER_STATE = in.getStringExtra(deliver_state);
DELIVER_ZIP_POSTAL = in.getStringExtra(deliver_zip_postal);
DELIVER_TO_SEE = in.getStringExtra(deliver_to_see);
DELIVER_ROOM = in.getStringExtra(deliver_room);
DELIVER_PHONE = in.getStringExtra(deliver_phone);
DELIVER_SPECIAL_INSTR = in.getStringExtra(deliver_special_instr);
}
@Override
protected void onResume() {
super.onResume();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
@Override
protected void onPause() {
super.onPause();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
@Override
public void onBackPressed() {
Intent i = new Intent(SingleMenuItemActivity.this, AgentPortalActivity.class);
startActivity(i);
SingleMenuItemActivity.this.finish();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
@Override
protected void onRestart() {
super.onRestart();
Intent i = new Intent(this, AgentPortalActivity.class);
startActivity(i);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
}
这里有一些图片可以帮助更好地解释情况。
例如,我点击了作业编号。 1642554 在 ListView 中,它会将我发送到下一个 Activity ,但如您所见,作业编号完全关闭(第二张带有 1642769 的图像实际上是 ListView 中的最后一个作业,并且将始终向我显示最后一个 Listview)
有什么建议吗?
按照 skUDA 的建议,这是我的日志:
07-17 08:37:17.158: W/dalvikvm(12096): threadid=1: thread exiting with uncaught exception (group=0x40015578)
07-17 08:37:17.162: E/AndroidRuntime(12096): FATAL EXCEPTION: main
07-17 08:37:17.162: E/AndroidRuntime(12096): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jetdelivery.mobile/com.jetdelivery.mobile.SingleMenuItemActivity}: java.lang.NullPointerException
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.os.Looper.loop(Looper.java:130)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-17 08:37:17.162: E/AndroidRuntime(12096): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 08:37:17.162: E/AndroidRuntime(12096): at java.lang.reflect.Method.invoke(Method.java:507)
07-17 08:37:17.162: E/AndroidRuntime(12096): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-17 08:37:17.162: E/AndroidRuntime(12096): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-17 08:37:17.162: E/AndroidRuntime(12096): at dalvik.system.NativeStart.main(Native Method)
07-17 08:37:17.162: E/AndroidRuntime(12096): Caused by: java.lang.NullPointerException
07-17 08:37:17.162: E/AndroidRuntime(12096): at com.jetdelivery.mobile.SingleMenuItemActivity.onCreate(SingleMenuItemActivity.java:146)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-17 08:37:17.162: E/AndroidRuntime(12096): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-17 08:37:17.162: E/AndroidRuntime(12096):
最佳答案
问题是您发送到 Intent 中的字符串(JOB、PAYS、READY_AT、DUE_BY 等)被设置为最后一个,因为这是最后创建的 View 。尝试
Object j = lv.getAdapter().getItem(position);
(其中对象是您的项目的任何数据类型)在您的 onItemClickListener 中,并从那里获取字符串值。
编辑:更详细的分割。
在进一步审查您的代码后,我发现了一个易于实现的解决方案。在您的 doInBackground 方法中,您将每个字符串设置为您从 JSONArray 获得的任何内容。由于您通过 Intent 发送这些字符串,因此您最终会得到下载和映射的最后一个作业。我的建议:采用 JSONArray JOBS 并将其声明为 Jobs 类中的字段变量。在这里,您的内部异步类和整个 Jobs 类都可以访问它。现在,将您的 onItemClickListener 更改为类似以下内容:
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long ide) {
vib.vibrate(40);
// Starting new intent
try {
Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);
in.putExtra("jobInfo", JOBS.getJSONObject(position).toString());
startActivity(in);
Jobs.this.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
} catch (Exception e) {
e.printStackTrace();
}
}
});
BlaineOmega 质疑您为何将如此多的额外数据放入您的 Intent 中是正确的。由于您正在使用 JSONObjects,只需将 JSONString 发送到您的下一个 Activity 。然后创建一个全局 JSONObject 并在你的 onCreate 中初始化它,如下所示:
myJsonJob = new JSONObject(getIntent().getStringExtra("jobInfo"));
现在您可以使用 JSONObject 方法直接访问您的数据,而不是从 Intent 中获取数据并将其存储在字符串变量中,然后使用这些字符串变量设置您的 TextView 。(顺便说一句,您几乎可以删除整个字符串可变的步骤,无论你如何去做,都可以
myTextView.setText(intent.getStringExtra("nameOfString"))
例如,在您的代码中,它将是:
trackno.setText(in.getStringExtra(job)).
不是将字符串分配给变量然后用变量设置它。它减少了内存使用和中间人的额外成本。)
这应该可以解决您的问题。
关于Android ListView 适配器在点击时显示最后一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11478951/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!