I have a ListView and I want to fill it with data that comes from another activity I bring the data by the intent but I do not know how to change the position of the new element to enlarge the list.
The .java of the first activity:
public class PrintActivity extends AppCompatActivity implements View.OnClickListener {
private String nombre;
private String ruc;
private String debt;
private String balance;
private String monto;
private String cobrador;
private String dir;
private double impue=0;
private double subt=0;
private String cont;
private String comentario;
private ArrayList<String> dato;
private TextView print_name;
private TextView print_fech;
private TextView print_regist;
private TextView print_address;
private TextView print_sub;
private TextView print_total;
private TextView print_imp;
private TextView print_cobra;
private EditText print_coment;
private Button btn_prints;
private Button btn_prints_more;
private String TAG="BluetoothDevice";
private BluetoothAdapter bAdapter;
private SharedPreferences settings;
private String recibo="000001";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
getIntetActivityDown();
setContentView(R.layout.activity_print);
initComponents();
}
private void bluetooth_exist() {
bAdapter = BluetoothAdapter.getDefaultAdapter();
if(bAdapter == null)
{
Log.w(TAG,getString(R.string.message_default_not_bluetooth));
return;
}
if(bAdapter.isEnabled())
Log.w(TAG,"Desactivando Bluetooth");
else
Log.w(TAG,"Activando Bluetooth");
}
private void getIntetActivityDown() {
nombre = getIntent().getStringExtra("nombre");
ruc = getIntent().getStringExtra("ruc");
dir = getIntent().getStringExtra("direccion");
monto = getIntent().getStringExtra("monto");
balance = getIntent().getStringExtra("saldo");
debt = getIntent().getStringExtra("deuda");
cobrador = getIntent().getStringExtra("responsable");
comentario= getIntent().getStringExtra("comentario");
cont = getIntent().getStringExtra("c");
}
private void initComponents() {
print_name = (TextView) findViewById(R.id.tv_print_name);
print_fech = (TextView) findViewById(R.id.tv_print_fecha);
print_regist = (TextView) findViewById(R.id.tv_print_recibo);
print_sub = (TextView) findViewById(R.id.tv_print_subtotal);
print_address = (TextView) findViewById(R.id.tv_print_address);
print_total = (TextView) findViewById(R.id.tv_print_total);
print_imp = (TextView) findViewById(R.id.tv_print_impuesto);
print_cobra = (TextView) findViewById(R.id.tv_print_cobrador);
print_coment = (EditText) findViewById(R.id.tv_print_coment);
btn_prints = (Button) findViewById(R.id.btn_print);
btn_prints_more = (Button) findViewById(R.id.btn_print_more);
String cobrador="nombre_cobrador";
double sub=0,imp=0,to=0;
int con=0;
to = Double.parseDouble(monto);
imp = Double.parseDouble(monto) * 0.1;
sub = to - imp ;
subt=sub = Utils.parceDecimal(sub);
impue=imp = Utils.parceDecimal(imp);
monto= String.valueOf(to = Utils.parceDecimal(to));
con= Integer.parseInt(cont)+1;
cont= String.valueOf(con);
print_fech.setText(Utils.dateFormatParcial());
print_name.setText(""+nombre);
print_regist.setText(""+cont);
print_regist.setText("00001");
print_address.setText(""+dir);
print_sub.setText(""+subt);
print_total.setText(""+monto);
print_imp.setText(""+impue);
print_cobra.setText(""+cobrador);
print_coment.setText(""+comentario);
btn_prints.setOnClickListener(this);
btn_prints_more.setOnClickListener(this);
}
@Override
public void onClick(View v) {
try {
switch (v.getId()){
case R.id.btn_print:
ViewLayoutPrint(0);
break;
case R.id.btn_print_more:
ViewLayoutPrint(1);
break;
default:
break;
}
}catch (Exception e){
Toast.makeText(this, R.string.message_error_click_print, Toast.LENGTH_SHORT).show();
}
}
private void ViewLayoutPrint(int value) {
comentario = String.valueOf(print_coment.getText());
switch (value) {
case 0:
bluetooth_exist();
if (bAdapter != null){
Toast.makeText(this, "Imprimiendo..", Toast.LENGTH_SHORT).show();
}else
Toast.makeText(this, R.string.message_no_print, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, HistoryPrintActivity.class);
view_data_print_history(intent);
startActivity(intent);
this.finish();
break;
case 1:
Log.e("PrintActivity",""+cont);
intent = new Intent(this, SearchPrintActivity.class);
view_data_print_history(intent);
startActivity(intent);
this.finish();
break;
default:
Log.i("PrintActivity","sin seleccion");
break;
}
}
private void view_data_print_history(Intent intent) {
String fecha=print_fech.getText().toString();
intent.putExtra("fecha",fecha);
intent.putExtra("nombre",nombre);
intent.putExtra("ruc",ruc);
intent.putExtra("deuda",debt);
intent.putExtra("direccion",dir);
intent.putExtra("saldo",balance);
intent.putExtra("monto",monto);
intent.putExtra("responsable",cobrador);
intent.putExtra("comentario",comentario);
intent.putExtra("impuesto",impue);
intent.putExtra("subtotal",subt);
intent.putExtra("recibo",recibo);
intent.putExtra("c",cont);
}
}
The .java of the second activity:
public class HistoryPrintActivity extends AppCompatActivity {
private ListView lv;
private RecyclerView rv;
private SharedPreferences settings;
private TextView tv;
private TextView vfecha,vnombre,vrecibo,vdireccion,vsubtotal,vimpuesto,vtotal,vcomentario;
private String nombre,ruc,debt,dir,balance,monto,cobrador,cont;
private String[] datos={"dato1"};
private ArrayList<String> data;
private ArrayAdapter<String> adapter;
Dialog customDialog = null;
private String fecha;
private String comentario;
int x=0;
private String impuesto;
private String subtotal;
private String recibo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_print);
x= Integer.parseInt(cont);
getIntetActivityDown();
initComponent();
datos[x]=""+ruc+" "+nombre;
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,datos);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
previewPrint();
}
});
}
private void getIntetActivityDown() {
fecha = getIntent().getStringExtra("fecha");
nombre = getIntent().getStringExtra("nombre");
ruc = getIntent().getStringExtra("ruc");
debt = getIntent().getStringExtra("deuda");
dir = getIntent().getStringExtra("direccion");
balance = getIntent().getStringExtra("saldo");
monto = getIntent().getStringExtra("monto");
impuesto = getIntent().getStringExtra("impuesto");
subtotal = getIntent().getStringExtra("subtotal");
recibo = getIntent().getStringExtra("recibo");
cobrador = getIntent().getStringExtra("responsable");
comentario = getIntent().getStringExtra("comentario");
cont = getIntent().getStringExtra("c");
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void previewPrint() {
LayoutInflater inflater = this.getLayoutInflater();
AlertDialog.Builder dialogo1 = new AlertDialog.Builder(HistoryPrintActivity.this);
dialogo1.setTitle("Vista previa del pago");
dialogo1.setView(inflater.inflate(R.layout.view_dialog_print, null));
dialogo1.setMessage(""+ruc+" "+nombre);
dialogo1.setCancelable(false);
dialogo1.setPositiveButton("Cerrar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogo1, int id) {
adapter.notifyDataSetChanged();
}
});
dialogo1.show();
}
private void initComponent() {
data=new ArrayList<String>();
data.add(""+ruc+" "+nombre);
}
}