我有一個使用ArrayAdapter的ListView,我也實現了getFilter
函數在ListView
內進行搜索。我正在使用SharedPreference
以獲得ListView
的索引以顯示有關下一個活動的一些信息。搜索時,如果索引不同,它會導致我的應用顯示錯誤的信息。當在ListView中使用getFilter時,SharedPreference得到錯誤的索引
case 0:
tvT = (TextView) findViewById(R.id.txtTitle);
strT = tvT.getText().toString();
inPos = strT.indexOf(".");
strT = strT.substring(0, inPos);
inPos = Integer.valueOf(strT);
Toast.makeText(getApplicationContext(), String.valueOf(inPos), 2000).show();
//moveToActivity(String.valueOf(inPos-1)); //0
break;
case 1:
tvT = (TextView) findViewById(R.id.txtTitle);
strT = tvT.getText().toString();
inPos = strT.indexOf(".");
strT = strT.substring(0, inPos);
inPos = Integer.valueOf(strT);
Toast.makeText(getApplicationContext(), String.valueOf(inPos), 2000).show();
//moveToActivity("1"); //1
break;
case 2:
tvT = (TextView) findViewById(R.id.txtTitle);
strT = tvT.getText().toString();
inPos = strT.indexOf(".");
strT = strT.substring(0, inPos);
inPos = Integer.valueOf(strT);
Toast.makeText(getApplicationContext(), String.valueOf(inPos), 2000).show();
//moveToActivity("2"); //2
break;
case 3:
tvT = (TextView) findViewById(R.id.txtTitle);
strT = tvT.getText().toString();
inPos = strT.indexOf(".");
strT2 = strT.substring(0, inPos);
inPos = Integer.valueOf(strT2);
Toast.makeText(getApplicationContext(), strT, 2000).show();
//moveToActivity("3"); //3
break;
case 4:
tvT = (TextView) findViewById(R.id.txtTitle);
strT = tvT.getText().toString();
inPos = strT.indexOf(".");
strT2 = strT.substring(0, inPos);
inPos = Integer.valueOf(strT2);
Toast.makeText(getApplicationContext(), String.valueOf(inPos), 2000).show();
//moveToActivity("4"); //4
break;
public void moveToActivity(String strWhich) {
editor.putString("NamePosition", strWhich);
editor.commit();
Intent myIntent = new Intent(MainActivity.this, NameDisplay.class);
startActivityForResult(myIntent, 0);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_out);
}
樣品我的活動:
的case 0
代碼工作,除了case 1
case 2
並依此類推,直到case 99
這是1相同INPOS如何讓這個不管位置是什麼,索引號碼總是保持不變?
我實際上擺脫了整個'Switch'的情況,它工作正常。 – Si8