我想要檢索的項目的的objectID(具體而言,這是一個名爲「房間」,在我們的解析模型類)一ListView
內點擊。 而在這之後,我想檢索對象ID傳遞到使用Intent
另一個類。檢索解析對象ID在OnTimeClickListener方法
我試圖解析文檔getObjectId();方法,但似乎不起作用。 我應該如何檢索它?
這是我的代碼。
Button createBtn;
Button searchBtn;
Button myGroupBtn;
Button settingBtn;
String[] courses;
List<String> listItems;
ArrayAdapter<String> adapter;
ListView listView;
TextView textView;
// when CREAT button is tapped
public void createBtn(View view){
Intent i = new Intent(getApplicationContext(), Create.class);
// Removes animation
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
}
// when Setting button is tapped
public void settingBtn(View view) {
Intent i = new Intent(getApplicationContext(), Setting.class);
// Removes animation
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String courseName = intent.getStringExtra("courseName");
String courseNumber = intent.getStringExtra("courseNumber");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_result);
// Making Links to Buttons on Create
createBtn = (Button) findViewById(R.id.createBtn);
searchBtn = (Button) findViewById(R.id.searchBtn);
myGroupBtn = (Button) findViewById(R.id.myGroupBtn);
settingBtn = (Button) findViewById(R.id.settingBtn);
//Chaning the button colors
searchBtn.setTextColor(0xFFFFFFFF);
createBtn.setTextColor(0xFFBFBFBF);
myGroupBtn.setTextColor(0xFFBFBFBF);
settingBtn.setTextColor(0xFFBFBFBF);
listView= (ListView)findViewById(R.id.listView);
textView= (TextView)findViewById(R.id.textView2);
textView.setText(courseName + " " + courseNumber);
listItems = new ArrayList<>();
ParseQuery<ParseObject> roomQuery = ParseQuery.getQuery("Room");
roomQuery.whereEqualTo("course" , courseName);
roomQuery.whereEqualTo("number" , courseNumber);
roomQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for (ParseObject room : objects) {
Log.i("Appinfo", String.valueOf(room.get("title")));
String stringToAdd = "";
String opened = String.valueOf(room.get("opened"));
String x;
if(opened.equals(true)){
x = "Open";
}else{
x = "Closed";
}
stringToAdd = stringToAdd + String.valueOf(room.get("studyDate")) + " " +
String.valueOf(room.get("category")) + " " + x + "\n"
+ String.valueOf(room.get("title")) +
" "
;
listItems.add(stringToAdd);
Log.i("Appinfo", "A");
}
} else {
Log.i("Appinfo", "B");
e.printStackTrace();
}
}
});
initList();
}
public void initList() {
Log.i("Appinfo", "C");
adapter = new ArrayAdapter<String>(this, R.layout.list_two, R.id.txtvw, listItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getApplicationContext(), Room.class);
String category = listItems.get(position);
}
}