显示passTert

时间:2015-10-16 04:59:56

标签: java android android-edittext textview

为什么namedate未显示在editText上?活动流程为WorkDetailsTable>> DisplayData>> UpdatePage

我在tableListener中实施了DisplayData。按下该行后,它将转到Update.java

WorkDetailsTable.java

 Button btn1 = (Button) findViewById(R.id.button2);
        btn1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(WorkDetailsTable.this);
                builder.setTitle("Data Saved");
                builder.setMessage("Are you sure you want to save?");
                builder.setIcon(android.R.drawable.ic_dialog_alert);
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int ii) {
                   if ((i != null && i.trim().length() > 0)) {
                    long ab = ts.insertTimeSheet(name, weather, date, status,b,i);
                    long cf= WF.insertWorkForce(subContractors, noPeople, noHours, ab);
                     WD.insertWorkDetails(a1, W1, P1, b, c,cf);
                     WD.insertWorkDetails(a2, W2, P2, d, e1,cf);
                     WD.insertWorkDetails(a3, W3, P3, f, g,cf);
                     WD.insertWorkDetails(a4, W4, P4, h, i,cf);
                     WF.insertWorkForce(subContractors, noPeople, noHours,cf);
                     Toast.makeText(getApplicationContext(), "4 Row has value", Toast.LENGTH_LONG).show();
                      Intent intent=new 

                     Intent(WorkDetailsTable.this,DisplayData.class);
                     intent.putExtra("name", name);
                     intent.putExtra("date",date);
                     startActivity(intent);
}
}

DisplayData.java

public class DisplayData extends AppCompatActivity {

    TableLayout table_layout;
    InfoAPI sqlcon;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.displaydata);
        MyDatabaseHelper db = new MyDatabaseHelper(this);
        InfoAPI I1 = new InfoAPI(this);
        sqlcon = new InfoAPI(this);


        //Table table=(TableLayout)findViewById(R.id.table)
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        table_layout = (TableLayout) findViewById(R.id.tableLayout1);
        final String name1 = getIntent().getExtras().getString("name");
        final String date=getIntent().getExtras().getString("date");
          BuildTable(name1,date);


    }


    private void BuildTable(String name,String date1)
    {
        final String name2 = name;
        final String date2=date1;
        sqlcon.open();
        Cursor c = sqlcon.readEntry(name2);

        int rows = c.getCount();
        int cols = c.getColumnCount();

        c.moveToFirst();

        TableRow rowDayLabels=new TableRow(this);
        TextView weather=new TextView(this);
        weather.setText("Weather");
        weather.setTypeface(Typeface.SERIF, Typeface.BOLD);

        TextView date=new TextView(this);
        date.setText("Date");
        date.setTypeface(Typeface.SERIF, Typeface.BOLD);

        TextView status=new TextView(this);
        status.setText("Status");
        status.setTypeface(Typeface.SERIF, Typeface.BOLD);

        TextView timeIn=new TextView(this);
        timeIn.setText("Time In");
        timeIn.setTypeface(Typeface.SERIF, Typeface.BOLD);

        TextView timeOut=new TextView(this);
        timeOut.setText("Time Out");
        timeOut.setTypeface(Typeface.SERIF, Typeface.BOLD);

        rowDayLabels.addView(weather);
        rowDayLabels.addView(date);
        rowDayLabels.addView(status);
        rowDayLabels.addView(timeIn);
        rowDayLabels.addView(timeOut);
        table_layout.addView(rowDayLabels);


        // outer for loop
        for (int i = 0; i < rows; i++) {

            TableRow row = new TableRow(this);
            row.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));

            // inner for loop
            for (int j = 0; j < cols; j++) {

                TextView tv = new TextView(this);
                tv.setLayoutParams(new TableRow.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                ));
               // tv.setBackgroundResource(R.drawable.cell_shape);
                tv.setGravity(Gravity.CENTER);
                tv.setTextSize(18);
                tv.setPadding(0, 5, 0, 5);

                tv.setText(c.getString(j));

                row.addView(tv);
                row.setBackgroundResource(R.drawable.color);

                row.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        Intent intent = new Intent(DisplayData.this, UpdatePage.class);
                        intent.putExtra("name", name2);
                        intent.putExtra("date",date2);
                        startActivity(intent);
                    }
                });

            }

            c.moveToNext();

            table_layout.addView(row);


        }
        sqlcon.close();
    }

        }

UpdatePage.java

public class UpdatePage extends AppCompatActivity {
    InfoAPI sqlcon;
    private SQLiteDatabase database;
    private MyDatabaseHelper dbHelper;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dbHelper = new MyDatabaseHelper(this);
        setContentView(R.layout.updatepage);
        final String name1 = getIntent().getExtras().getString("name2");
        final String date = getIntent().getExtras().getString("date2");
        RetrievePage(name1, date);
    }


    public void RetrievePage(String name, String date) {
        final String name2 = name;
        final String date2 = date;
        database = dbHelper.getWritableDatabase();
        final EditText name3 = (EditText) findViewById(R.id.editText9);
        final EditText date3 = (EditText) findViewById(R.id.editText12);
        name3.setText(name2);
        date3.setText(date2);
}
}

1 个答案:

答案 0 :(得分:0)

从WorkDetailsTable发送名称和日期&gt;&gt; DisplayData时,您正在使用密钥&#34; name&#34;和&#34;日期&#34;正确,用于保存和检索相同的密钥。

但是从DisplayData&gt;&gt; UpdatePage发送名称和日期时,您没有使用相同的密钥来保存和检索您的代码的显示内容

 row.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        Intent intent = new Intent(DisplayData.this, UpdatePage.class);
                        intent.putExtra("name", name2);
                        intent.putExtra("date",date2);
                        startActivity(intent);
                    }
                });

在onCreate内的UpdatePage中

    final String name1 = getIntent().getExtras().getString("name2");
    final String date = getIntent().getExtras().getString("date2");

查看按键。例如&#34; name&#34;和&#34; name2&#34;所以使用相同的密钥 将代码更改为

    final String name1 = getIntent().getExtras().getString("name");
    final String date = getIntent().getExtras().getString("date");

然后检查您是否正在获取数据