我想要的是从工具栏微调器中选择的特定数字接收文本。但我无法在arraylist中显示它。如果我在equalsIgnoreCase("06123456")
中放置文本,它会返回文本,但是如果我将字符串String item = adapterView.getItemAtPosition(i).toString();
放入其中则不返回任何内容。没有在logcat中找到的错误。这是我的微调器和光标的源代码:
toolbarSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
write = (EditText) findViewById(R.id.edittext);
write.setTextColor(Color.BLACK);
btnWrite = (Button) findViewById(R.id.buttonSend);
btnWrite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message = write.getText().toString();
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
});
ListView chatList = (ListView) findViewById(R.id.chat);
ArrayList<ChatData> listChat = new ArrayList<ChatData>();
ContentResolver contentResolver = getContentResolver();
Cursor cursor2 = contentResolver.query(Uri.parse("content://sms/inbox"), null, null, null, null);
int indexBody = cursor2.getColumnIndex("body");
if (indexBody < 0 || !cursor2.moveToFirst()) return;
while (cursor2.moveToNext()) {
do {
//display sms inbox by number
String number = cursor2.getString(cursor2.getColumnIndex("address"));
String item = adapterView.getItemAtPosition(i).toString();
if (number.equalsIgnoreCase(item)) {
String str = cursor2.getString(indexBody);
listChat.add(new ChatData(str, false));
}
} while (cursor2.moveToNext());
}
ChatRecAdapter adapter = new ChatRecAdapter(MainActivity.this, listChat);
chatList.setAdapter(adapter);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
//do nothing
}
});
提前致谢!