0
我正在開發中,我不得不從一個ListView控件通過單擊第一個ListView.The第二屆活動的ListView移動到另一個ListView控件的應用程序是一個肯定的圖標圖像和一個自定義的ListView TextView中。圖像圖標是在啓動和點擊列表項相應的圖像會變得Visible.2nd的ListView後看不見的是單一的點擊列表視圖。![在這裏輸入的形象描述] [1] 當我點擊後退按鈕,再點擊了首先ListView控件,第2的ListView成爲無形的被點擊項目..如何管理自定義的ListView項目的狀態
我在Android的新的,不知道我怎麼有管理的ListItem點擊的狀態。 PLZ幫助...... 我必須從第一個屏幕移動到第二屏幕,並保持ListView項的狀態時reclick是在1日ListView項作出。
第二列表視圖活動
SharedPreferences pref;
private static String names[] = {"SV3","SV4","SV6","LV1"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selectibx);
lv=(ListView)findViewById(R.id.listView1);
adapter = new LvCustomAdapter(this, names);
lv.setAdapter(adapter);
LoadSelections();
ImageView img=(ImageView) lv.findViewById(R.id.image);
if(img!=null)
{
img.setImageResource(R.drawable.black_arrow);
img.setVisibility(View.VISIBLE);
}
lv.setOnItemClickListener(this);
back=(ImageView)findViewById(R.id.imageback);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent = new Intent(getApplicationContext(),MainActivity.class);
Bundle b=new Bundle();
b.putString("state", "clicked");
intent.putExtras(b);
setResult(RESULT_OK, intent);
startActivity(intent);
finish();
}
});
}
public void onItemClick(AdapterView<?> lvv, View view, int position, long id) {
if (current != -1) {
View last = lvv.getChildAt(current); // the last one clicked
last.findViewById(R.id.image).setVisibility(View.GONE);
}
view.findViewById(R.id.image).setVisibility(View.VISIBLE);
current = position; // remember the new clicked position
System.out.println("Selected State is: "+current);
SaveSelections(view);
}
private void SaveSelections(View v) {
// TODO Auto-generated method stub
SharedPreferences settings = getSharedPreferences(PREFS_NAME,0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("Raman", current);
editor.commit();
}
private void LoadSelections() {
pref = this.getApplicationContext().getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE);
int xy=pref.getInt("Raman",1);
adapter = new LvCustomAdapter(this, names);
lv.setAdapter(adapter);
lv.setSelection(xy);
System.out.println(lv.getSelectedItemPosition()+"****"+xy);
View v=lv.getChildAt(xy);
}
}
自定義適配器類:
public class LvCustomAdapter extends BaseAdapter {
protected ListView mListView;
public String title[];
//public String designations[];
public Activity context;
public LayoutInflater inflater;
int current=-1;
public LvCustomAdapter(Activity context,String[] title) {
super();
this.context = context;
this.title = title;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
// TODO Auto-generated method stub
return title.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public static class ViewHolder
{
ImageView imgarrow;
TextView txtViewName;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView==null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.commonlist, null);
holder.txtViewName = (TextView) convertView.findViewById(R.id.tvItem);
holder.imgarrow = (ImageView) convertView.findViewById(R.id.image);
/* holder.email.setOnClickListener(emailClickListener);
holder.mobile.setOnClickListener(mobileClickListener);
holder.phone.setOnClickListener(phoneClickListener);
convertView.setTag(holder); */
//int a=convertView.getSelectedItemPosition();
int a=position;
convertView.setTag(holder);
}
else
holder=(ViewHolder)convertView.getTag();
holder.txtViewName.setText(title[position]);
holder.imgarrow.setImageResource(R.drawable.black_arrow);
holder.imgarrow.setVisibility(View.INVISIBLE);
return convertView;
}
}
感謝....
我的工作就像你說的,這爲我工作。 – user1381420RKS