PDA

View Full Version : مشکل با سرچ کاستوم لیست ویو



morahimi
چهارشنبه 24 تیر 1394, 17:11 عصر
سلام دوستان من یه لیست ویو شخصی دارم که سرچ رو توش پیاده کردم لیست طوری تنظیم شده که وقتی کاربر روی آیتمی کلیک کرد پوزیشن اون آیتم برای اکتیویتی بعد ارسال بشه در حالت درست کار میکنه اما امان از وقتی که سرچ میکنم همیشه پوزیشن رو یک بر می گردونه چکار کنم ؟؟؟؟؟؟؟؟؟؟//
اینم کد کامل :
ListView list;
SharedPreferences sh;
EditText inputSearch;
CustomList adapter;
ArrayAdapter<String> adapter2;
String[] web = {"بنز","مزدا","سایپا","ایران خودرو"};
String r,t,ro,ta;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
//-----------فراخوانی ها ----------------------
sh = getSharedPreferences("font", MODE_PRIVATE);
inputSearch = (EditText) findViewById(R.id.inputSearch);
SharedPreferences shared = getSharedPreferences("act", MODE_PRIVATE);
final String active = shared.getString("active", "no");
if (active.equals("yes")){
Adad.setDisabled(true);
};
ro = sh.getString("r", "no");
if (ro.equals("yes")){
getWindow().addFlags(WindowManager.LayoutParams.FL AG_KEEP_SCREEN_ON);
}
else{};
ta = sh.getString("t", "no");
if (ta.equals("yes")){
getWindow().setFlags(WindowManager.LayoutParams.FL AG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
//--------------------ست کردن آداپتر با لیست ویو---------------------
adapter = new CustomList(List.this, web);
adapter2 = new ArrayAdapter<String>(this, R.layout.item, R.id.txt_name, web);
list = (ListView) findViewById(R.id.listView1);
list.setAdapter(adapter);
//--------------------فعالسازی اکشن بار-------------------------
ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText("سلام");
ImageButton imageButton = (ImageButton) mCustomView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
setview();
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
//------------------------- درستورات سرچ------------------------------
inputSearch.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
List.this.adapter2.getFilter().filter(cs);
list.setAdapter(adapter2);
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub

}
});
//--------------------رویداد کلیک لیست ویو (تابع on click)-------------------
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(active.equals("yes")){
SharedPreferences.Editor shpE = sh.edit();
int m = position+1;
String str = String.valueOf(m);
String ab = String.valueOf(id);
shpE.putString("matn",(str));
shpE.commit();
Intent intent = new Intent(List.this, Matn.class);
Bundle bndlanimation =
ActivityOptions.makeCustomAnimation(getApplication Context(), R.anim.animation, R.anim.animation2).toBundle();
startActivity(intent, bndlanimation);

}
else if(active.equals("no")&&position>69){
SharedPreferences.Editor shpE = sh.edit();
int m = position+1;
String str = String.valueOf(m);
String ab = String.valueOf(id);
shpE.putString("matn",(str));
shpE.commit();
Intent intent = new Intent(List.this, Matn.class);
Bundle bndlanimation =
ActivityOptions.makeCustomAnimation(getApplication Context(), R.anim.animation, R.anim.animation2).toBundle();
startActivity(intent, bndlanimation);

}
else{displayactivealert();}
}

});
}