Это моя операция просмотра, в которой я хочу извлечь данные из другой таблицы и сохранить обработанные данные в другую таблицу. Проблема заключается в том, что данные добавляются снова и снова, и в действии представления одни и те же данные повторяются и заполняют все пространство.
public class LastActivity extends AppCompatActivity {
TextView txt;
Button btn;
static MyDB myDB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_last);
myDB = new MyDB(this);
getSupportActionBar().setTitle("Final Data");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final LinearLayout lm = (LinearLayout) findViewById(R.id.lastactivity);
btn = (Button) findViewById(R.id.subfielddata);
txt = (TextView) findViewById(R.id.textView7);
Bundle bundle = getIntent().getExtras();
String date2 = bundle.getString("date1");
txt.setText(date2);
//create the layout parameters
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor c = Secondlast_Activity.myDB.getAllTime();
c.moveToFirst();
if (c == null) {
Toast.makeText(getApplicationContext(), "Error!! Cursor is empty", Toast.LENGTH_SHORT).show();
} else {
//create all variants to fetch data from database
while (c.moveToNext()) {
String ename = c.getString(0);
int h1 = c.getInt(1);
int h2 = c.getInt(5);
int m1 = c.getInt(2);
int m2 = c.getInt(6);
int ad = c.getInt(7);
int wages = c.getInt(3);
int a, b, d;
int min = 0, res, hr;
//oode for getting hours from edit text
hr = h1 - h2;
//code for converting values to edit text value to minutes
if (m1 > m2) {
a = 60 - m1;
m2 = a + m2;
min = m2;
hr--;
} else {
if (m1 < m2) {
b = m2 - m1;
min = b;
}
}
hr = hr * (-1);
wages = wages * hr;
//oode for getting hours from edit text
hr = h1 - h2;
//code for converting values to edit text value to minutes
if (m1 > m2) {
a = 60 - m1;
m2 = a + m2;
min = m2;
hr--;
} else {
if (m1 < m2) {
b = m2 - m1;
min = b;
}
}
hr = hr * (-1);
wages = wages * hr;
boolean result = Secondlast_Activity.myDB.insertData(ename,hr, wages);
if (result) {
Toast.makeText(LastActivity.this, hr + " Insertion Complete", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(LastActivity.this, "Error!!", Toast.LENGTH_LONG).show();
}
}
}
}
});
//creating cursor for database to let data in count
Cursor c = LastActivity.myDB.getLastData();
c.moveToFirst();
if (c == null) {
Toast.makeText(getApplicationContext(), "Cursor d is empty!!", Toast.LENGTH_SHORT).show();
} else {
//create all variants to fetch data from database
while (c.moveToNext()) {
final String emname = c.getString(0);
final int totalwork = c.getInt(2);
final int Advance = c.getInt(3);
final int totalearn = c.getInt(4);
//create linear layout
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
//create textView to show data
TextView Name = new TextView(this);
Name.setText(emname + "");
Name.setWidth(250);
ll.addView(Name);
TextView work = new TextView(this);
work.setText(totalwork + "");
work.setWidth(290);
ll.addView(work);
TextView Ad = new TextView(this);
Ad.setText(Advance + "");
Ad.setWidth(290);
ll.addView(Ad);
TextView earn = new TextView(this);
earn.setText(totalearn + "");
earn.setWidth(250);
ll.addView(earn);
Name.setLayoutParams(params);
lm.addView(ll);
}
}
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return super.onSupportNavigateUp();
}
}