gpt4 book ai didi

android - 每次加载 Activity 时, ListView 都会加倍。

转载 作者:行者123 更新时间:2023-11-29 01:59:07 25 4
gpt4 key购买 nike

每次加载 Activity 时,listview 都会加倍(每次都会填充以前的数据,使数据出现两次)

public class FragmentActivity extends Activity implements OnItemClickListener{

private ListView discrepancy_list;
private DiscrepancyListAdapter list_adapter = null;
private ArrayList<CommonEntity> discrepancyList = new ArrayList<CommonEntity>();
private RelativeLayout objRelativeLayout;
private static int X_CO_ordinate;
private static int Y_CO_ordinate;
private ArrayList<String> arrlstCo_ordinate;
private ArrayList<String> arrlst_Count;
private boolean touch = true,isOnLaunch = false;
private int editText_ID=1,count=1;
private EditText objEditText;
private SortedMap<Integer,String> mapDefect=null;
private int final_position;
private ImageButton objImageButton;
private DatabaseHandler db;
Bitmap StoredBitmap;
Drawable StoredDrawable;
private static int dataSet = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapDefect=new TreeMap<Integer, String>();
arrlstCo_ordinate=new ArrayList<String>();
arrlst_Count=new ArrayList<String>();
discrepancy_list = (ListView)findViewById(R.id.number_list);
discrepancy_list.setOnItemClickListener(this);
db = new DatabaseHandler(this);

objRelativeLayout=(RelativeLayout) findViewById(R.id.RelativeLayout);
objRelativeLayout.setOnTouchListener(new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
String strEditText;
if(!checkForDataSaved()){
if(touch){
Log.d("ON", "onTouch called");
X_CO_ordinate=(int) event.getX() ;
Y_CO_ordinate=(int) event.getY();

boolean isNotDuplicate=checkDuplicateElement(X_CO_ordinate,Y_CO_ordinate);
if(isNotDuplicate){
Log.d("TOUCH", "TOUCH"+X_CO_ordinate+"|"+Y_CO_ordinate+"|"+"Touch :");
if(objEditText != null){
strEditText=objEditText.getText().toString();
Log.d("Err", "EditText not null"+strEditText);

if(strEditText != null && strEditText.length() != 0){
// if(chekMapEntry(objEditText.getId(), objEditText.getText().toString(), ""+X_CO_ordinate+"|"+Y_CO_ordinate))
// {
arrlst_Count.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
arrlstCo_ordinate.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
mapDefect.put(objEditText.getId(),objEditText.getText().toString());
Log.d("Err", "In Touch Map Size :"+mapDefect.size() +"Arr List Size :"+arrlstCo_ordinate.size());
objEditText.setVisibility(View.INVISIBLE);
//}else{Toast.makeText(FragmentActivity.this, "Duplicate map entry", Toast.LENGTH_LONG).show();}
addEditText();
Log.d("Err", "String not null");
}else{
Log.d("Err", "String null");
Toast.makeText(FragmentActivity.this, "Please log the defect ::: in onTouch()", Toast.LENGTH_LONG).show();
}
}else{
Log.d("Err", "EditText null");
arrlst_Count.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
arrlstCo_ordinate.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
Log.d("Err", "In Touch else Map Size :"+mapDefect.size() +"Arr List Size :"+arrlstCo_ordinate.size());
Drawable relative_image_bg = objRelativeLayout.getBackground();
Bitmap bitmap = ((BitmapDrawable)relative_image_bg).getBitmap();
Bitmap bitmap2 = ((BitmapDrawable)(getResources().getDrawable(R.drawable.no_image_screen_new))).getBitmap();

if(bitmap.sameAs(bitmap2)){
Toast.makeText(FragmentActivity.this, "Please capture the image", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(FragmentActivity.this, "Not equal..", Toast.LENGTH_LONG).show();
addEditText();
}
}
}
touch=false;
}else{
touch=true;
}
}
return true;
}

private boolean checkDuplicateElement(int x_CO_ordinate,int y_CO_ordinate){
String strX=String.valueOf(x_CO_ordinate);
String strY=String.valueOf(y_CO_ordinate);

for(int i=0;i<arrlstCo_ordinate.size();i++){
String strResult=arrlstCo_ordinate.get(i);
String []arrResult=StringUtils.split(strResult, "|");
String strTemp_X=arrResult[0];
String strTemp_Y=arrResult[1];
Log.d("CO", ""+strTemp_X+strTemp_Y+"|"+strX+strY);

if(strTemp_X.equalsIgnoreCase(strX) || strTemp_Y.equalsIgnoreCase(strY)){
Log.d("DUP", "Duplicate element is not allow");
Toast.makeText(FragmentActivity.this, "Duplicate element is not allow", Toast.LENGTH_SHORT).show();
return false;
}
}
return true;
}
});

//add list in main.xml

addList();
getDefects();


}

private void addList(){


discrepancyList = LocalDatabaseOperations.callDBToGetList(this);

list_adapter = new DiscrepancyListAdapter(this, discrepancyList);
discrepancy_list.setAdapter(list_adapter);
isOnLaunch = true;
discrepancy_list.performItemClick(null, 0, discrepancy_list.getFirstVisiblePosition());


}

private void getDefects(){

if(LocalDatabaseOperations.callDBToGetDefects(this) == true){
fechCoordinate();
addViewEditText();

}
}

因此,这是在 LHS 上加载“差异列表”并在 fragment 的 RHS 上加载列表中第一项信息的 Activity 。但是当我返回并返回到此屏幕时,会加载相同的 Activity 以使其加载 Activity 。这应该发生。但是,之前的数据也存在,使整个数据翻了一番。

最佳答案

在您的 callDBToGetList() 函数中,我假设您正在返回一个列表(比如 myList)。将此行作为 callDBToGetList() 函数的第一行。

myList.clear();

将 myList 替换为您要返回的列表的名称。

关于android - 每次加载 Activity 时, ListView 都会加倍。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13577669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com