每次加载活动时,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 上加载“差异列表”的活动,并在片段的 RHS 上加载有关列表中第一项的信息。但是当我返回并返回此屏幕时,会加载相同的活动,使其加载活动。这应该发生。然而,先前的数据也存在,使整个数据翻倍。