Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get value in textview in method onItemClickListener in android
    primarykey
    data
    text
    <p>I had some problem in my code, I hope someone can help me, OK we are just on the issue of his :</p> <p>This is the code of my main page</p> <pre><code> ----------------------------------------------------- package com.buanasoft.toko; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.os.AsyncTask; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView; public class f_penjualan extends Activity { private long rowID; private TextView nm_barangTv; private TextView hargaTv; private TextView h_jualTv; private TextView satuanTv; private TextView stokTv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.f_penjualan); setUpViews(); Bundle extras = getIntent().getExtras(); rowID = extras.getLong(f_data.ROW_ID); Button go = (Button)findViewById(R.id.btn_pilih); Intent i = this.getIntent(); go.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(getApplicationContext(), daftar_barang.class); startActivity(i); } }); } private void setUpViews() { nm_barangTv = (TextView) findViewById(R.id.namaBarangText); hargaTv = (TextView) findViewById(R.id.hargaBarangText); h_jualTv = (TextView) findViewById(R.id.hargaJualText); satuanTv = (TextView) findViewById(R.id.satuanText); stokTv = (TextView) findViewById(R.id.stokText); } @Override protected void onResume() { super.onResume(); new LoadBarang().execute(rowID); } private class LoadBarang extends AsyncTask&lt;Long, Object, Cursor&gt; { DBCon_barang dbCon_barang = new DBCon_barang(f_penjualan.this); @Override protected Cursor doInBackground(Long... params) { dbCon_barang.open(); return dbCon_barang.getOneBarang(params[0]); } @Override protected void onPostExecute(Cursor result) { super.onPostExecute(result); result.moveToFirst(); // get the column index for each data item int nm_barangIndex = result.getColumnIndex("nm_barang"); int hargaIndex = result.getColumnIndex("harga"); int h_jualIndex = result.getColumnIndex("h_jual"); int satuanIndex = result.getColumnIndex("satuan"); int stokIndex = result.getColumnIndex("stok"); nm_barangTv.setText(result.getString(nm_barangIndex)); hargaTv.setText(result.getString(hargaIndex)); h_jualTv.setText(result.getString(h_jualIndex)); satuanTv.setText(result.getString(satuanIndex)); stokTv.setText(result.getString(stokIndex)); result.close(); dbCon_barang.close(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.det_data_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.editItem: Intent addEditBarang = new Intent(this, AddEditBarang.class); addEditBarang.putExtra(f_data.ROW_ID, rowID); addEditBarang.putExtra("nm_barang", nm_barangTv.getText()); addEditBarang.putExtra("harga", hargaTv.getText()); addEditBarang.putExtra("h_jual", h_jualTv.getText()); addEditBarang.putExtra("satuan", satuanTv.getText()); addEditBarang.putExtra("stok", stokTv.getText()); startActivity(addEditBarang); return true; case R.id.deleteItem: deleteBarang(); return true; default: return super.onOptionsItemSelected(item); } } private void deleteBarang() { AlertDialog.Builder alert = new AlertDialog.Builder(f_penjualan.this); alert.setTitle(R.string.confirmTitle); alert.setMessage(R.string.confirmMessage); alert.setPositiveButton(R.string.delete_btn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int button) { final DBCon_barang dbCon_barang = new DBCon_barang (f_penjualan.this); AsyncTask&lt;Long, Object, Object&gt; deleteTask = new AsyncTask&lt;Long, Object, Object&gt;() { @Override protected Object doInBackground(Long... params) { dbCon_barang.deleteBarang(params[0]); return null; } @Override protected void onPostExecute(Object result) { finish(); } }; deleteTask.execute(new Long[] { rowID }); } } ); alert.setNegativeButton(R.string.cancel_btn, null).show(); } } </code></pre> <p>and this is the code from my second activity</p> <pre><code>---------------------------------------------------------- public class daftar_barang extends ListActivity { public static final String ROW_ID = "row_id"; private ListView conListView; private CursorAdapter conAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ////script untuk memampilkan daftar barang &amp; menu conListView=getListView(); conListView.setOnItemClickListener(viewConListener); // mengisi value di TextView String[] from = new String[] { "nm_barang" }; int[] to = new int[] { R.id.daftar_barang }; conAdapter = new SimpleCursorAdapter(daftar_barang.this, R.layout.daftar_barang, null, from, to); setListAdapter(conAdapter); // set adapter } @Override protected void onResume() { super.onResume(); new GetData().execute((Object[]) null); } @Override protected void onStop() { Cursor cursor = conAdapter.getCursor(); if (cursor != null) cursor.deactivate(); conAdapter.changeCursor(null); super.onStop(); } private class GetData extends AsyncTask&lt;Object, Object, Cursor&gt; { DBCon_barang dbConnector = new DBCon_barang(daftar_barang.this); @Override protected Cursor doInBackground(Object... params) { dbConnector.open(); return dbConnector.getAllBarang(); } @Override protected void onPostExecute(Cursor result) { conAdapter.changeCursor(result); // set the adapter's Cursor dbConnector.close(); } } //fungsi untuk melihat detail barang OnItemClickListener viewConListener = new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,long arg3) { Intent viewCon = new Intent(daftar_barang.this,f_penjualan.class); viewCon.putExtra(ROW_ID, arg3); startActivity(viewCon); } }; } </code></pre> <p>Her problem is = <br> I want to display the data item from my second activity to first activity. so by the time I get into the second activity and I click on one of the data in the second activity, he will be on show to the first activity. <br> in a section of code no error warning, but after my build, my application errors when I open the activity.</p> <p>please let me know the location of his problems: (</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload