動的に作成されたテーブル行を削除しようとしていますが、正しいテーブル行 ID を取得できません。すべてのテーブル行に同じ ID があり、作成したものよりも多く、カウンターがより高い ID を設定し、すべての行がそれを取得します...助けていただければ幸いです。これで数日間立ち往生しています。私の方法は大きいですが、最初だけが重要だと思います。
public void getRow(String klik, int brojkica)
{
//db=openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE, null);
db = INF.getReadableDatabase();
int count = 0;
Cursor cursor3 = db.rawQuery("select id,Artikl, CIJENA from Artikli where");
System.out.println(counterko);
counterko++;
tr = new TableRow(this);
tr.setClickable(true);
tr.setBackgroundColor(Color.GRAY);
tr.setId(500 + counterko);
cursor3.moveToFirst();
final TextView sifracolumn = new TextView(this);
sifracolumn.setId(1000 + counterko);
sifracolumn.setPadding(5, 5, 5, 5);
sifracolumn.setText(String.valueOf(cursor3.getInt(0)));
sifracolumn.setGravity(Gravity.CENTER | Gravity.BOTTOM);
sifracolumn.setTextColor(Color.BLACK);
tr.addView(sifracolumn);
allIDs.add(sifracolumn);//////////////////////////////////////
final TextView artiklcolumn = new TextView(this);
artiklcolumn.setPadding(5, 5, 5, 5);
artiklcolumn.setId(2000 + counterko);
artiklcolumn.setClickable(true);
artiklcolumn.setWidth(400);
artiklcolumn.setText(cursor3.getString(1));
artiklcolumn.setGravity(Gravity.CENTER | Gravity.BOTTOM);
artiklcolumn.setTextColor(Color.BLACK);
tr.addView(artiklcolumn);
artiklcolumn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
//alert(tr.getId());
alert(artiklcolumn.getId());
}
});
final TextView cijenacolumn = new TextView(this);
cijenacolumn.setId(3000 + count);
cijenacolumn.setText(cursor3.getString(2));
cijenacolumn.setWidth(120);
cijenacolumn.setGravity(Gravity.CENTER | Gravity.BOTTOM);
cijenacolumn.setTextColor(Color.BLACK);
tr.addView(cijenacolumn);
final EditText kolicinacolumn = new EditText(this);
kolicinacolumn.setId(4000 + counterko);
kolicinacolumn.setText("1");
kolicinacolumn.setGravity(Gravity.CENTER | Gravity.BOTTOM);
kolicinacolumn.setTextColor(Color.BLACK);
allEds.add(kolicinacolumn);
tr.addView(kolicinacolumn);
final TextView iznoscolumn = new TextView(this);
iznoscolumn.setId(5000 + counterko);
iznoscolumn.setWidth(120);
iznoscolumn.setText("");
iznoscolumn.setTextColor(Color.BLACK);
iznoscolumn.setGravity(Gravity.CENTER | Gravity.BOTTOM);
tr.addView(iznoscolumn);
allTexts.add(iznoscolumn);
if (kolicinacolumn.getText().toString() == "1")
{
System.out.println("kme");
iznoscolumn.setText(cijenacolumn.getText().toString());
}
zaplatiti();
tl = (TableLayout) findViewById(R.id.tableLayout1);
tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
count++;
kolicinacolumn.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before, int count)
{
String kol = kolicinacolumn.getText().toString();
if (TextUtils.isEmpty(kol))
{
try
{
System.out.print("Stop it");
} catch (NumberFormatException e)
{
System.out.println("This is not a number");
System.out.println(e.getMessage());
}
} else
{
Float racunam = Float.valueOf(kol);
Float racunam2 = Float.valueOf(cijenacolumn.getText().toString());
Float reza = racunam * racunam2;
iznoscolumn.setText(String.valueOf(reza));
}
zaplatiti();
}
public void afterTextChanged(Editable s)
{
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
//TODO
}
});
}