I have a Listview. I want to order it such that when new item added they add at top. I try
Collections.reverse(ListElementsArrayList);
And it works. But after (second,third click,....) it mix all earlier item.Is this possible. If yes help me.
My MainActivity is
package com.pradeep.ap;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class AP extends AppCompatActivity {
EditText A, B, D, N, AN;
Button a, b, d, n, an, AP, GP, HP;
int Count = 0;
ListView LV;
String[] ListElements = new String[]{};
List<String> ListElementsArrayList;
ArrayAdapter<String> adapter;
Handler handler;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ap);
A = (EditText) findViewById(R.id.eta);
B = (EditText) findViewById(R.id.etb);
D = (EditText) findViewById(R.id.etd);
N = (EditText) findViewById(R.id.etn);
AN = (EditText) findViewById(R.id.etan);
AP = (Button) findViewById(R.id.apap);
GP = (Button) findViewById(R.id.apgp);
HP = (Button) findViewById(R.id.aphp);
a = (Button) findViewById(R.id.a);
b = (Button) findViewById(R.id.b);
d = (Button) findViewById(R.id.d);
n = (Button) findViewById(R.id.n);
an = (Button) findViewById(R.id.an);
LV = (ListView) findViewById(R.id.lv);
handler = new Handler();
ListElementsArrayList = new ArrayList<String>(Arrays.asList(ListElements));
adapter = new ArrayAdapter<String>(AP.this,android.R.layout.simple_list_item_1,
ListElementsArrayList);
LV.setAdapter(adapter);
adapter.notifyDataSetChanged();
a.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
float numb = 0;
float numd = 0;
float numleal=0;
float result = 0;
int Result;
if (TextUtils.isEmpty(B.getText().toString())
|| TextUtils.isEmpty(D.getText().toString())) {
return;
}
numb = Float.parseFloat(B.getText().toString());
numd = Float.parseFloat(D.getText().toString());
ListElementsArrayList.add(" First term of AP is = " + A.getText().toString());
result = numb - numd;
Count = LV.getAdapter().getCount() + 1;
Result = (int) result;
A.setText("" + Result);
adapter.notifyDataSetChanged();
Collections.reverse(ListElementsArrayList);
}
});
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
float numa = 0;
float numd = 0;
float result = 0;
int Result;
Count = LV.getAdapter().getCount() + 1;
if (TextUtils.isEmpty(A.getText().toString())
|| TextUtils.isEmpty(D.getText().toString())) {
return;
}
numa = Float.parseFloat(A.getText().toString());
numd = Float.parseFloat(D.getText().toString());
result = numa + numd;
Result = (int) result;
B.setText("" + Result);
ListElementsArrayList.add(" Second term of AP is = " + B.getText().toString());
adapter.notifyDataSetChanged();
Collections.reverse(ListElementsArrayList);
}
});
d.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
float numa = 0;
float numb = 0;
float result = 0;
int Result;
if (TextUtils.isEmpty(A.getText().toString())
|| TextUtils.isEmpty(B.getText().toString())) {
return;
}
numa = Float.parseFloat(A.getText().toString());
numb = Float.parseFloat(B.getText().toString());
result = numb - numa;
Result = (int) result;
Count = LV.getAdapter().getCount() + 1;
D.setText("" + Result);
ListElementsArrayList.add(" Value of D is = " + D.getText().toString());
adapter.notifyDataSetChanged();
Collections.reverse(ListElementsArrayList);
}
});
n.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
float numa = 0;
float numd = 0;
float numan = 0;
float result = 0;
int Result;
if (TextUtils.isEmpty(A.getText().toString())
|| TextUtils.isEmpty(D.getText().toString())
|| TextUtils.isEmpty(AN.getText().toString())) {
return;
}
numa = Float.parseFloat(A.getText().toString());
numd = Float.parseFloat(D.getText().toString());
numan = Float.parseFloat(AN.getText().toString());
result = ((numan - numa) / numd) + 1;
Result = (int) result;
Count = LV.getAdapter().getCount() + 1;
N.setText("" + Result);
ListElementsArrayList.add(" Number of term/terms in this AP is = " + N.getText().toString());
adapter.notifyDataSetChanged();
Collections.reverse(ListElementsArrayList);
}
});
an.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
float numa = 0;
float numd = 0;
float numn = 0;
float result = 0;
int Result;
if (TextUtils.isEmpty(A.getText().toString())
|| TextUtils.isEmpty(D.getText().toString())
|| TextUtils.isEmpty(N.getText().toString())) {
return;
}
numa = Float.parseFloat(A.getText().toString());
numd = Float.parseFloat(D.getText().toString());
numn = Float.parseFloat(N.getText().toString());
result = ((numn - 1) * numd) + numa;
Result = (int) result;
AN.setText("" + Result);
Count = LV.getAdapter().getCount() + 1;
ListElementsArrayList.add(" Term/Terms of this AP is = " + AN.getText().toString());
adapter.notifyDataSetChanged();
adapter.getCount();
Collections.reverse(ListElementsArrayList);
}
});
}
}
Just use
List.add(0, element)
to add an element as first element of a list. As described in the documentation.
Related
i have a cartactivity and cartadapter, in cartadapter i add increment and decrement for each stuff, and i sum it in total price and total weight and send it to activity ( it worked by passing textview activity from cartactivity to adapteractivity ) and now i want to get seperated quantity for each item to send to database with format Example if item is ( Wallet, Bag, Shoes ) then quanitity that will send to database like this ( 2, 3, 3) 2 represent for wallet and (,) for seperating item quantity, 3 represent bag, and 3 represent shoes. i don't know how to take each quantity and send it in a format like that
have a look on my adapter
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;
import androidx.annotation.NonNull;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.cepheuen.elegantnumberbutton.view.ElegantNumberButton;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Currency;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import app.gify.co.id.R;
import app.gify.co.id.activity.List_Kado;
import app.gify.co.id.modal.MadolCart;
public class AdapterCart extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
ArrayList<MadolCart> carts;
MadolCart mm;
View view;
View viewku;
Context context;
int kuantitas;
String totalname;
int totalBerat, totalharga;
TextView totalhargas, totalberats;
public AdapterCart(ArrayList<MadolCart> carts, Context context, TextView totalhargas, TextView totalberats) {
this.carts = carts;
this.context = context;
this.totalhargas = totalhargas;
this.totalberats = totalberats;
}
public class MyCart extends RecyclerView.ViewHolder {
public ImageView gambar, tambah, kurang;
public TextView harga, nama, quantitas;
public RelativeLayout background, foreground;
public ElegantNumberButton quantity;
public MyCart(#NonNull View itemView) {
super(itemView);
gambar = itemView.findViewById(R.id.gambarcart);
tambah = itemView.findViewById(R.id.tambahcart);
kurang = itemView.findViewById(R.id.kurangcart);
harga = itemView.findViewById(R.id.hargacart);
nama = itemView.findViewById(R.id.namacart);
quantitas = itemView.findViewById(R.id.quantitas);
background = itemView.findViewById(R.id.background);
foreground = itemView.findViewById(R.id.foreground);
quantity = itemView.findViewById(R.id.quantity);
}
}
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_cart, parent, false);
viewku = LayoutInflater.from(parent.getContext()).inflate(R.layout.cart, parent, false);
return new MyCart(view);
}
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
kuantitas = carts.get(position).getJumlah();
int hargaku = carts.get(position).getHarga() * kuantitas;
for (int a = 0; a < carts.size(); a++){
Log.d("cartsizeku", "onBindViewHolder: " + carts.size()+ " s " + carts.get(a).getNamacart() + " s " + carts.get(a).getHarga());
String nama = carts.get(position).getNamacart();
if (nama.equals(carts.get(a).getNamacart())){
totalhargas.setText(String.valueOf(totalCart(carts, carts.get(a).getNamacart())));
totalberats.setText(String.valueOf(beratCart(carts, carts.get(a).getNamacart())));
}
}
Locale locale = new Locale("id", "ID");
NumberFormat format = NumberFormat.getCurrencyInstance(locale);
((MyCart)holder).harga.setText(format.format(Double.valueOf(hargaku)));
((MyCart)holder).nama.setText(carts.get(position).getNamacart());
Glide.with(view).load(carts.get(position).getGambar()).into(((MyCart)holder).gambar);
Intent intent = new Intent("message_subject_intent");
// intent.putExtra("name", String.valueOf((totalCart(carts))));
intent.putExtra("title", String.valueOf((getName(carts))));
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
((MyCart) holder).tambah.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int count = Integer.parseInt(((MyCart) holder).quantitas.getText().toString());
if (count<9){
count+=1;
((MyCart)holder).quantitas.setText(String.valueOf(count));
int harga = carts.get(position).getHarga()*count;
((MyCart)holder).harga.setText(String.valueOf(format.format(Double.valueOf(harga))));
String nama = carts.get(position).getNamacart();
totalhargas.setText(String.valueOf(totalCart(carts, nama)));
totalberats.setText(String.valueOf(beratCart(carts, nama)));
}
// ((MyCart)holder).quantitas.setText(String.valueOf(kuantitas));
int total = hargaku * kuantitas;
Intent intents = new Intent("message_subject_intent");
intents.putExtra("name", String.valueOf((getName(carts))));
LocalBroadcastManager.getInstance(context).sendBroadcast(intents);
}
});
((MyCart) holder).kurang.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int count = Integer.parseInt(((MyCart)holder).quantitas.getText().toString());
if (count>1){
count-=1;
((MyCart)holder).quantitas.setText(String.valueOf(count));
int harga = carts.get(position).getHarga()*count;
((MyCart)holder).harga.setText(String.valueOf(format.format(Double.valueOf(harga))));
String nama = carts.get(position).getNamacart();
totalhargas.setText(String.valueOf(kurangtotalcart(carts, nama)));
totalberats.setText(String.valueOf(kurangberatCart(carts, nama)));
}
// ((MyCart)holder).quantitas.setText(String.valueOf(kuantitas));
int total = hargaku * kuantitas;
Intent intents = new Intent("message_subject_intent");
intents.putExtra("name", String.valueOf((getName(carts))));
LocalBroadcastManager.getInstance(context).sendBroadcast(intents);
}
});
}
#Override
public int getItemCount() {
return carts.size();
}
public int totalCart(ArrayList<MadolCart> items, String name){
for(int i = 0 ; i < items.size(); i++) {
totalname = items.get(i).getNamacart();
if (totalname.equals(name)){
totalharga += items.get(i).getHarga();
}
}
return totalharga;
}
public int kurangtotalcart(ArrayList<MadolCart> items, String name){
for(int i = 0 ; i < items.size(); i++) {
totalname = items.get(i).getNamacart();
if (totalname.equals(name)){
totalharga -= items.get(i).getHarga();
}
}
return totalharga;
}
public int beratCart(ArrayList<MadolCart> items, String name){
for(int i = 0 ; i < items.size(); i++) {
totalname = items.get(i).getNamacart();
if (totalname.equals(name)){
totalBerat += items.get(i).getBerat();
}
}
return totalBerat;
}
public int kurangberatCart(ArrayList<MadolCart> items, String name){
for(int i = 0 ; i < items.size(); i++) {
totalname = items.get(i).getNamacart();
if (totalname.equals(name)){
totalBerat -= items.get(i).getBerat();
}
}
return totalBerat;
}
public String getName(List<MadolCart> name){
String ku = "";
for (int i = 0; i < name.size(); i++){
ku += name.get(i).getNamacart() + ", ";
}
return ku;
}
public void removeItem(int item){
carts.remove(item);
notifyItemRemoved(item);
}
public void restoreItem(MadolCart madolCart, int item){
carts.add(item, madolCart);
notifyItemInserted(item);
}
public void quantityPlus(MadolCart madolCart, int item){
}
}
and this is my activity
package app.gify.co.id.activity;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.FragmentTransaction;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.SpannedString;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.DrawableImageViewTarget;
import com.google.android.material.navigation.NavigationView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Currency;
import java.util.Locale;
import java.util.Random;
import app.gify.co.id.R;
import app.gify.co.id.adapter.AdapterCart;
import app.gify.co.id.modal.MadolCart;
//import app.gify.co.id.thirdparty.GMailSender;
//import app.gify.co.id.thirdparty.SenderAgent;
import app.gify.co.id.widgets.RecyclerTouchDelete;
import static app.gify.co.id.baseurl.UrlJson.DELETECART;
import static app.gify.co.id.baseurl.UrlJson.GETBARANG;
import static app.gify.co.id.baseurl.UrlJson.GETCART;
public class CartActivity extends AppCompatActivity implements RecyclerTouchDelete.RecyclerTouchListener{
Button Checkout, lanjutBelanja;
ImageView backCart;
TextView totalbelanjar, totalberat;
AdapterCart adapterCart;
ArrayList<MadolCart> madolCarts;
String namacart, gambarcart, uidku;
GridLayoutManager glm;
RecyclerView recyclerView;
MainActivity mainActivity;
NavigationView navigationView;
public int hargaku, beratku, kuantitas, lastNumber, idbarang, getHargaAwal;
SharedPreferences preferences;
SharedPreferences.Editor editor;
Spanned templateConvert;
NumberFormat format;
Locale id;
Random random;
String template, idberat, idharga;
private Dialog dialog;
LayoutInflater inflater;
ImageView goku;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cart);
lanjutBelanja = findViewById(R.id.lanjutBelanjaChart);
lanjutBelanja.setOnClickListener(v -> {
Intent intent = new Intent(getApplicationContext(), List_Kado.class);
startActivity(intent);
});
getHargaAwal = getIntent().getIntExtra("harga", 0);
Log.d("setHarga", getHargaAwal + "");
dialog = new Dialog(CartActivity.this);
inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.loading, null);
goku = layout.findViewById(R.id.custom_loading_imageView);
goku.animate().rotationBy(360).setDuration(3000).setInterpolator(new LinearInterpolator()).start();
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.setCancelable(false);
dialog.setContentView(layout);
dialog.show();
id = new Locale("id", "ID");
format = NumberFormat.getCurrencyInstance(id);
random = new Random();
lastNumber = 0;
for (int k = 0; k < 3; k++){
lastNumber+=(random.nextInt(10)*Math.pow(10, k));
}
backCart = findViewById(R.id.backCartNav);
backCart.setOnClickListener(v -> finish());
Checkout = findViewById(R.id.checkoutChart);
totalbelanjar = findViewById(R.id.totalBelanjaChart);
totalberat = findViewById(R.id.totalBeratChart);
recyclerView = findViewById(R.id.rvChart);
preferences = PreferenceManager.getDefaultSharedPreferences(CartActivity.this);
uidku = preferences.getString("uid", "");
madolCarts = new ArrayList<>();
getCart();
glm = new GridLayoutManager(CartActivity.this, 1);
recyclerView.setLayoutManager(glm);
Checkout.setOnClickListener(view -> {
Intent intent = new Intent(CartActivity.this, CheckoutActivity.class);
intent.putExtra("idharga", idharga);
intent.putExtra("name", namacart);
preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
editor = preferences.edit();
editor.remove("range");
editor.remove("acara");
editor.remove("buat");
editor.apply();
startActivity(intent);
});
LocalBroadcastManager.getInstance(this).registerReceiver(passValue, new IntentFilter("message_subject_intent"));
ItemTouchHelper.SimpleCallback callback = new RecyclerTouchDelete(0, ItemTouchHelper.LEFT, this);
new ItemTouchHelper(callback).attachToRecyclerView(recyclerView);
}
public String LoadData(String inFile) {
String tContents = "";
try {
InputStream stream = getAssets().open(inFile);
int size = stream.available();
byte[] buffer = new byte[size];
stream.read(buffer);
stream.close();
tContents = new String(buffer);
} catch (IOException e) {
// Handle exceptions here
}
return tContents;
}
private String replaceNumberOfAmount(String original, int replace){
return original.substring(0, original.length() - 3) + replace;
}
// private void senderEmail(){
// SenderAgent senderAgent = new SenderAgent("gify.firebase#gmail.com", "Confirmation Transaction Gify", templateConvert, CartActivity.this);
// senderAgent.execute();
// }
private void getCart(){
JsonObjectRequest objectRequest = new JsonObjectRequest(Request.Method.GET, GETCART, null, response -> {
try {
JSONArray array = response.getJSONArray("YukNgaji");
for (int a = 0; a < array.length(); a++){
JSONObject object = array.getJSONObject(a);
String id_tetap = object.getString("id_tetap");
if (id_tetap.equalsIgnoreCase(uidku)){
kuantitas = object.getInt("jumlah");
idbarang = object.getInt("id_barang");
idharga = object.getString("harga");
idberat = object.getString("berat");
getBerat(idbarang);
dialog.dismiss();
}
}
dialog.dismiss();
} catch (JSONException e) {
e.printStackTrace();
}
}, error -> {
Log.d("getcart", "getCart: " + error.getMessage());
});
RequestQueue queue = Volley.newRequestQueue(CartActivity.this);
queue.add(objectRequest);
}
public BroadcastReceiver passValue = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
namacart = intent.getStringExtra("name");
Log.d("hargalast", namacart + "");
namacart = intent.getStringExtra("title");
template = "<h2> Gify Transaction </h2> " +
"<h3> Kamu baru saja melakukan pesanan dengan detail sebagai berikut </h3>"
+ "<p><b> Nama barang: </p></b>"
+ "<p><b> Harga barang" + format.format(Double.valueOf(replaceNumberOfAmount(idharga, lastNumber))) + ". Silahkan transfer dengan tiga digit terakhir yaitu :" + lastNumber + "</p></b>"
+ "<p><b> Jika sudah melakukan pembayaran, silahkan konfirmasi disini </p></b>"
+ "https://api.whatsapp.com/send?phone=082325328732&text=Confirmation%20Text"
+ "<h2>Salam, Gify Team</h2>";
Log.d("hargalast", idharga + lastNumber);
templateConvert = Html.fromHtml(template);
}
};
private void getBerat(int idbarang){
JsonObjectRequest objectRequest = new JsonObjectRequest(Request.Method.GET, GETBARANG, null, response -> {
try {
JSONArray array = response.getJSONArray("YukNgaji");
for (int a = 0; a < array.length(); a++){
JSONObject object = array.getJSONObject(a);
int id_barang = object.getInt("id");
if (idbarang==id_barang){
String gambar = object.getString("photo");
int harga = object.getInt("harga");
String namacart = object.getString("nama");
int berat = object.getInt("berat");
MadolCart madolCart = new MadolCart(gambar, harga, namacart, idbarang, kuantitas, berat);
madolCarts.add(madolCart);
adapterCart = new AdapterCart(madolCarts, CartActivity.this, totalbelanjar, totalberat);
recyclerView.setAdapter(adapterCart);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}, error -> {
Log.d("jsoner", "getBerat: " + error.getMessage());
});
RequestQueue queue = Volley.newRequestQueue(CartActivity.this);
queue.add(objectRequest);
}
#Override
public void onSwipe(RecyclerView.ViewHolder viewHolder, int dir, int pos) {
if (viewHolder instanceof AdapterCart.MyCart){
String name = madolCarts.get(viewHolder.getAdapterPosition()).getNamacart();
MadolCart madolCart = madolCarts.get(viewHolder.getAdapterPosition());
int deleteIndex = viewHolder.getAdapterPosition();
Log.d("taptap", "onSwipe: " + madolCarts.get(viewHolder.getAdapterPosition()).getNamacart());
GETBARANG(madolCarts.get(viewHolder.getAdapterPosition()).getNamacart());
adapterCart.removeItem(viewHolder.getAdapterPosition());
}
}
private void deletecart(String id_barang){
StringRequest stringRequest = new StringRequest(Request.Method.GET, DELETECART+"?idtetap="+uidku+"&idbarang="+id_barang, response -> {
try {
if (response.equalsIgnoreCase("bisa")){
Toast.makeText(CartActivity.this, "Barang telah di hapus", Toast.LENGTH_SHORT).show();
Log.d("bisabarangcart", "GETBARANG: " );
}
}catch (Exception e){
Log.d("ekscartactivity", "deletecart: " + e.getMessage());
}
}, error -> {
Log.d("ernocartdel", "deletecart: " + error.getMessage());
});
RequestQueue queue = Volley.newRequestQueue(CartActivity.this);
queue.add(stringRequest);
}
private void GETBARANG(String namas){
JsonObjectRequest objectRequest = new JsonObjectRequest(Request.Method.GET, GETBARANG,null, response -> {
try {
JSONArray array = response.getJSONArray("YukNgaji");
for (int a = 0; a < array.length(); a++){
JSONObject object = array.getJSONObject(a);
String nama = object.getString("nama");
if (nama.equalsIgnoreCase(namas)){
Log.d("namabarang", "GETBARANG: " + nama + " s " + namas);
String id = object.getString("id");
deletecart(id);
}
}
}catch (Exception e){
Log.d("barangexce", "GETBARANG: " + e.getMessage());
}
}, error -> {
Log.d("errorgetbrng", "GETBARANG: " + error.getMessage());
});
RequestQueue queue = Volley.newRequestQueue(CartActivity.this);
queue.add(objectRequest);
}
}
to make sum of total prices i used this code
public int totalCart(ArrayList<MadolCart> items, String name){
for(int i = 0 ; i < items.size(); i++) {
totalname = items.get(i).getNamacart();
if (totalname.equals(name)){
totalharga += items.get(i).getHarga();
}
}
return totalharga;
}
i put summing code in a method, and call the method on if button + is clicked
if button - is clicked it will call this method
public int kurangtotalcart(ArrayList<MadolCart> items, String name){
for(int i = 0 ; i < items.size(); i++) {
totalname = items.get(i).getNamacart();
if (totalname.equals(name)){
totalharga -= items.get(i).getHarga();
}
}
return totalharga;
}
and now idk how to get seperated quanitity for each position / item in recycler view then send it to activity as format ( 1, 2, 3) (,) mean a seperator for each item
How to get value seperated quantity from recycler view item position?
SOLVED
public String getSeperatedquantity(List<MadolCart> quantity){
String kus = "";
for (int i = 0; i < quantity.size(); i++){
kus += quantity.get(i).getQuantity() + ", ";
}
return kus;
}
I found the solution by adding this:
public String getSeperatedquantity(List<MadolCart> quantity){
String kus = "";
for (int i = 0; i < quantity.size(); i++){
kus += quantity.get(i).getQuantity() + ", ";
}
return kus;
}
My app is trying to make some calculations and checking for a condition and printing the array of numbers which satisfy the condition.But the app is closing on click.Please help..
package com.example.ganesha.app1;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import static android.R.attr.button;
public class MainActivity extends AppCompatActivity {
private Button result;
private EditText cap,pwfac,dis,solution;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
result = (Button) findViewById(R.id.resbut);
cap = (EditText) findViewById(R.id.capacity);
pwfac = (EditText) findViewById(R.id.powerfactor);
dis = (EditText) findViewById(R.id.distance);
solution = (EditText) findViewById(R.id.result);
//mytextview = (TextView)findViewById(R.id.result)
result.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Double capacity = Double.valueOf(cap.getText().toString());
Double powerfactor = Double.valueOf(pwfac.getText().toString());
Double distance = Double.valueOf(dis.getText().toString());
Double amps = capacity / (718.80 * powerfactor);
Double minimum = 24.9;
Double ampspermtr=amps/distance;
Double[] cases = {26.8156, 16.4013, 10.2083, 6.8180, 4.0509, 2.5470, 1.6151, 1.1689, 0.8673, 0.6075, 0.4458, 0.3616, 0.3028, 0.2532, 0.2082, 0.1812, 0.1604, 0.1461, 0.1359};
Double [] volts=new Double[19];
for(int i = 0; i <19; i++)
{
volts[i]=cases[i]*ampspermtr;
}
Double [] wires={1.50,2.50,4.0,6.0,10.0,16.0,25.0,35.0,50.0,70.0,95.0,120.0,150.0,185.0,240.0,300.0,400.0,500.0,630.0};
final Double [] allpossible = new Double[19];
int c=0;
for(int j=0;j<19;j++)
{
if(volts[j]<minimum)
{
allpossible[c]=wires[j];
}
c++;
}
final int g= c;
for(int p=0;p<g;p++)
{
String value = Double.toString(allpossible[g]);
solution.append(value);
}
}
});
It is based on electrical Engineering.Can someone find the mistake and help me out
Actually there some Exception occurred in you calculation in
OnClick of Button you should write the Calculation code surround
with try catch block like Below
try{
Double capacity = Double.valueOf(cap.getText().toString());
Double powerfactor = Double.valueOf(pwfac.getText().toString());
Double distance = Double.valueOf(dis.getText().toString());
Double amps = capacity / (718.80 * powerfactor);
Double minimum = 24.9;
Double ampspermtr=amps/distance;
Double[] cases = {26.8156, 16.4013, 10.2083, 6.8180, 4.0509, 2.5470, 1.6151, 1.1689, 0.8673, 0.6075, 0.4458, 0.3616, 0.3028, 0.2532, 0.2082, 0.1812, 0.1604, 0.1461, 0.1359};
Double [] volts=new Double[19];
for(int i = 0; i <19; i++)
{
volts[i]=cases[i]*ampspermtr;
}
Double [] wires={1.50,2.50,4.0,6.0,10.0,16.0,25.0,35.0,50.0,70.0,95.0,120.0,150.0,185.0,240.0,300.0,400.0,500.0,630.0};
final Double [] allpossible = new Double[19];
int c=0;
for(int j=0;j<19;j++)
{
if(volts[j]<minimum)
{
allpossible[c]=wires[j];
}
c++;
}
final int g= c;
for(int p=0;p<g;p++)
{
String value = Double.toString(allpossible[g]);
solution.append(value);
}
}
}Catch(Exception ex){
// handle your Exception here
}
Hi I want to open a activity when a if statement comes true. like "if gameStatus are equal to 12, then open scoreActivity". The Code:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.GridLayout;
import java.util.Random;
import android.os.Build;
import android.os.Handler;
public class Game6x4Activity extends AppCompatActivity implements View.OnClickListener {
private int numberOfElements;
private int[] buttonGraphicLocations;
private MemoryButton selectedButton1;
private MemoryButton selectedButton2;
private boolean isBusy = false;
public int gameStatus;
public int gameScore;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_mode);
gameScore = 0;
gameStatus = 0;
GridLayout gridLayout = (GridLayout)findViewById(R.id.grid_layout_6x4);
int numColumns = gridLayout.getColumnCount();
int numRow = gridLayout.getRowCount();
numberOfElements = numColumns * numRow;
MemoryButton[] buttons = new MemoryButton[numberOfElements];
int[] buttonGraphics = new int[numberOfElements / 2];
buttonGraphics[0] = R.drawable.card1;
buttonGraphics[1] = R.drawable.card2;
buttonGraphics[2] = R.drawable.card3;
buttonGraphics[3] = R.drawable.card4;
buttonGraphics[4] = R.drawable.card5;
buttonGraphics[5] = R.drawable.card6;
buttonGraphics[6] = R.drawable.card7;
buttonGraphics[7] = R.drawable.card8;
buttonGraphics[8] = R.drawable.card9;
buttonGraphics[9] = R.drawable.card10;
buttonGraphics[10] = R.drawable.card11;
buttonGraphics[11] = R.drawable.card12;
buttonGraphicLocations = new int[numberOfElements];
shuffleButtonGraphics();
for(int r=0; r < numRow; r++)
{
for(int c=0; c <numColumns; c++)
{
MemoryButton tempButton = new MemoryButton(this, r, c, buttonGraphics[buttonGraphicLocations[r * numColumns + c]]);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
tempButton.setId(View.generateViewId());
}
tempButton.setOnClickListener(this);
buttons[r * numColumns + c] = tempButton;
gridLayout.addView(tempButton);
}
}
}
protected void shuffleButtonGraphics(){
Random rand = new Random();
for (int i=0; i < numberOfElements; i++)
{
buttonGraphicLocations[i] = i % (numberOfElements / 2);
}
for (int i=0; i < numberOfElements; i++)
{
int temp = buttonGraphicLocations[i];
int swapIndex = rand.nextInt(16);
buttonGraphicLocations[i] = buttonGraphicLocations[swapIndex];
buttonGraphicLocations[swapIndex] = temp;
}
}
private int buttonGraphicLocations(int i) {
return 0;
}
#Override
public void onClick(View view) {
if(isBusy) {
return;
}
MemoryButton button = (MemoryButton) view;
if(button.isMatched) {
return;
}
if(selectedButton1 == null)
{
selectedButton1 = button;
selectedButton1.flip();
return;
}
if(selectedButton1.getId()== button.getId())
{
return;
}
if (selectedButton1.getFrontDrawableId()== button.getFrontDrawableId())
{
button.flip();
button.setMatched(true);
if (selectedButton1 != null) {
selectedButton1.setEnabled(false);
System.out.println("not null");
}
else{
System.out.println("null");
}
if (selectedButton2 != null) {
selectedButton2.setEnabled(false);
System.out.println("not null");
}
else{
System.out.println("null");
}
gameStatus = gameStatus + 1;
gameScore = gameScore + 10;
if (gameStatus == 12){
Intent it = new Intent(Game6x4Activity.this, ActivityScore.class);
startActivity(it);
}
selectedButton1 = null;
return;
}
else
{
selectedButton2 = button;
selectedButton2.flip();
isBusy = true;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run(){
selectedButton2.flip();
selectedButton1.flip();
selectedButton1 = null;
selectedButton2 = null;
isBusy = false;
}
},500);
return;
}
}
}
The activity that i want to open will show to the player his score. the activity is equal to all game modes, there will be some test to the app understant what path should go on. test like this one:
"
if (gameStatus == 12) {
gameScore = gameScore*55;
TextView scoreText = (TextView) findViewById(R.id.textView8);
scoreText.setText(gameScore);
}
else if (gameStatus == 15){
"
There are 4 game modes: This is the 6x4 game, where we can find 24 cards (12 images).
else if (gameStatus == 15){
Intent intent = new Intent(Game6x4Activity.this, NextActivity.class);
startActivity(intent);
}
I think, you are asking for this. You can pass value to another activity with
intent.putExtra("key",desired value);
So, I have a spinner, populated with ~35 values. If I select, say, the fifth item, then when it is selected, it does what it is supposed to do (populate a second spinner). My problem is that shortly afterwards (<1/2 second) it reverts the values in the second spinner to what they would be if option 1 in the first spinner were selected. The fifth item in the first spinner is still selected but it acts as though the first item gets selected twice per second.
I've tried everything I could find on this (barely anything) and nothing has worked so far. This basically has me stuck on going further in my app.
Entire Code:
package com.nicotera.colton.londontransitguide;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.*;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class RoutesActivity extends Activity implements OnItemSelectedListener {
Spinner dirSpinner;
Spinner routeSpinner;
static String [] namedDirections = new String [2];
private static final String TAG = "RoutesActivity";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_routes);
dirSpinner = (Spinner) findViewById(R.id.route_direction_spinner); // Create an ArrayAdapter using the string array and a default spinner layout
routeSpinner = (Spinner) findViewById(R.id.route_name_spinner); // Create an ArrayAdapter using the string array and a default spinner layout
routeSpinner.setOnItemSelectedListener(this);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.routes_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner
routeSpinner.setAdapter(adapter);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Log.i(TAG, "Item selected");
//DecimalFormat df = new DecimalFormat("00##");
int tempPos = pos;
Log.i(TAG, ("Position of selected item: " + tempPos));
int routeSelected;
if (tempPos < 17)
routeSelected = (tempPos + 1);
else if (tempPos >= 17 && tempPos < 29)
routeSelected = (tempPos + 2);
else
routeSelected = (tempPos + 3);
String temp;
if (routeSelected < 10)
temp = ("0") + routeSelected;
else
temp = ("") + routeSelected;
String url = "http://www.ltconline.ca/WebWatch/MobileAda.aspx?r=" + temp;
new MyInnerClass().execute(url);
}
public void directionSpinner (String directions []) {
int temp;
for (int i = 1; i <=2; i++)
{
temp = Integer.parseInt(directions[i]);
if (temp == 1)
namedDirections[(i-1)] = "Eastbound";
else if (temp == 2)
namedDirections[(i-1)] = "Northbound";
else if (temp == 3)
namedDirections[(i-1)] = "Southbound";
else if (temp == 4)
namedDirections[(i-1)] = "Westbound";
}
//setContentView(R.layout.activity_routes);
dirSpinner.setOnItemSelectedListener(this);
ArrayAdapter<CharSequence> adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.add(namedDirections[0]);
adapter.add(namedDirections[1]);
dirSpinner.setAdapter(adapter);
Log.i(TAG, "spinner populated");
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
class MyInnerClass extends AsyncTask<String, Void, String> {
String [] directions = new String [3];
String [] directionNames = new String [3];
private static final String TAG = "RoutesActivity";
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
RoutesActivity.this.directionSpinner(directions);
}
#Override
protected String doInBackground(String... params) {
try{
Pattern routeDirPattern = Pattern.compile("\\&d=(\\d{1,2})");
Connection conn = Jsoup.connect(params[0]);
Document doc = conn.get();
int i = 0;
Elements routeLinks = doc.select("a[href]");
for (Element routeLink : routeLinks) {
i = (i + 1);
String name = routeLink.text();
Attributes attrs = routeLink.attributes();
String href = attrs.get("href");
Matcher m = routeDirPattern.matcher(href);
if (m.find()) {
String number = m.group(1);
directions [i] = number;
directionNames [i] = name;
Log.i(TAG, directionNames [i]);
}
}
}catch(Exception e){Log.d("doinbackground exception", e.toString());}
return ("Done");
}
}
}
I was using the same onselected listener for both without an if statement to check which one was clicked so it just thought that the first one was clicked.
This is the corrected code:
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Spinner spnr = (Spinner) parent;
Log.i(TAG, "Item selected");
switch(parent.getId()) {
case R.id.route_name_spinner:
//DecimalFormat df = new DecimalFormat("00##");
int tempPos = pos;
Log.i(TAG, ("Position of selected item: " + tempPos));
int routeSelected;
if (tempPos < 17)
routeSelected = (tempPos + 1);
else if (tempPos >= 17 && tempPos < 29)
routeSelected = (tempPos + 2);
else
routeSelected = (tempPos + 3);
String temp;
if (routeSelected < 10)
temp = ("0") + routeSelected;
else
temp = ("") + routeSelected;
String url = "http://www.ltconline.ca/WebWatch/MobileAda.aspx?r=" + temp;
new MyInnerClass().execute(url);
case R.id.route_direction_spinner:
}
}
I have an Activity with a RadioGroup which contains 2 RadioButtons (rdbtn4, rdbtn5).
Then I have a XML file which contains to LinearLayouts:
linlay4 just contains 4 Spinners,
linlay5 five additional Spinners.
Then the user can set the Spinners as he likes and after pressing a button 2 TextViews are set with specific text (depends on the chosen Spinner values).
This is working flawlessly with linlay4, with linlay5 chosen the TextViews aren't set.
This is my code:
package at.esdev.electro;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
public class Widerstandsfarbcode extends Activity
{
LinearLayout linlay4rings, linlay5rings;
TextView tvWidResultValue, tvWidToleranzValue;
Button btnCalcwid;
Spinner sp4Farbe1, sp4Farbe2, sp4Farbe3, sp4Farbe4, sp5Farbe1, sp5Farbe2, sp5Farbe3, sp5Farbe4, sp5Farbe5;
RadioGroup rdGrp1;
RadioButton rdbtn4rings, rdbtn5rings;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.widerstandsfarbcode);
linlay4rings = (LinearLayout) findViewById(R.id.linLay4rings);
linlay5rings = (LinearLayout) findViewById(R.id.linLay5rings);
tvWidResultValue = (TextView) findViewById(R.id.tvWidResultValue);
tvWidToleranzValue = (TextView) findViewById(R.id.tvWidToleranzValue);
btnCalcwid = (Button) findViewById(R.id.btnCalcwid);
sp4Farbe1 = (Spinner) findViewById(R.id.sp4Farbe1);
sp4Farbe2 = (Spinner) findViewById(R.id.sp4Farbe2);
sp4Farbe3 = (Spinner) findViewById(R.id.sp4Farbe3);
sp4Farbe4 = (Spinner) findViewById(R.id.sp4Farbe4);
sp5Farbe1 = (Spinner) findViewById(R.id.sp5Farbe1);
sp5Farbe2 = (Spinner) findViewById(R.id.sp5Farbe2);
sp5Farbe3 = (Spinner) findViewById(R.id.sp5Farbe3);
sp5Farbe4 = (Spinner) findViewById(R.id.sp5Farbe4);
sp5Farbe5 = (Spinner) findViewById(R.id.sp5Farbe5);
rdGrp1 = (RadioGroup) findViewById(R.id.rdGrp1);
rdbtn4rings = (RadioButton) findViewById(R.id.rdb4Rings);
rdbtn5rings = (RadioButton) findViewById(R.id.rdb5Rings);
//Default-Value when starting Activity:
linlay4rings.setVisibility(0); //0 = visible, 4 = invisible, 8 = gone
linlay5rings.setVisibility(8);
//Layout for 5 buttons disabled, if rdbtn4 is selected:
rdbtn4rings.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
linlay4rings.setVisibility(0); //0 = visible, 4 = invisible, 8 = gone
linlay5rings.setVisibility(8);
}
});
//Layout for 4 buttons disabled, if rdbtn5 is selected:
rdbtn5rings.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
linlay4rings.setVisibility(8); //0 = visible, 4 = invisible, 8 = gone
linlay5rings.setVisibility(0);
}
});
//Color-adjusting
ArrayAdapter <?> adapterFarben = ArrayAdapter.createFromResource(this, R.array.widerstandsfarbSpinnerItems, android.R.layout.simple_spinner_item);
adapterFarben.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp4Farbe1.setAdapter(adapterFarben);
sp4Farbe2.setAdapter(adapterFarben);
sp5Farbe1.setAdapter(adapterFarben);
sp5Farbe2.setAdapter(adapterFarben);
sp5Farbe3.setAdapter(adapterFarben);
//Multiplier-adjusting
ArrayAdapter <?> adapterMultiplikator = ArrayAdapter.createFromResource(this, R.array.widerstandsMultiplikatorSpinnerItems, android.R.layout.simple_spinner_item);
adapterMultiplikator.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp4Farbe3.setAdapter(adapterMultiplikator);
sp5Farbe4.setAdapter(adapterMultiplikator);
//Tolerance-adjusting:
ArrayAdapter <?> adapterToleranz = ArrayAdapter.createFromResource(this, R.array.widerstandsToleranzSpinnerItems, android.R.layout.simple_spinner_item);
adapterFarben.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp4Farbe4.setAdapter(adapterToleranz);
sp5Farbe5.setAdapter(adapterToleranz);
if (rdbtn4rings.isChecked())
{
btnCalcwid.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String s41 = String.valueOf(sp4Farbe1.getSelectedItemId()); //Farbe 1
String s42 = String.valueOf(sp4Farbe2.getSelectedItemId()); //Farbe 2
String s43 = String.valueOf(sp4Farbe3.getSelectedItemId()); //Multiplikator
String s44 = String.valueOf(sp4Farbe4.getSelectedItemId()); //Toleranz
int ds43 = Integer.parseInt(s43);
int ds44 = Integer.parseInt(s44);
rise1(ds43);
String snewTolerance = String.valueOf(getToleranceValue(ds44));
//Output:
tvWidResultValue.setText("" + s41 + s42 + "*10^" + ds43 + " Ohm");
tvWidToleranzValue.setText(""+ snewTolerance + " %");
}
});
}
if (rdbtn5rings.isChecked())
{
btnCalcwid.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String s51 = String.valueOf(sp5Farbe1.getSelectedItemId()); //Farbe 1
String s52 = String.valueOf(sp5Farbe2.getSelectedItemId()); //Farbe 2
String s53 = String.valueOf(sp5Farbe3.getSelectedItemId()); //Farbe 3
String s54 = String.valueOf(sp5Farbe4.getSelectedItemId()); //Multiplikator
String s55 = String.valueOf(sp5Farbe5.getSelectedItemId()); //Toleranz
int ds54 = Integer.parseInt(s54);
int ds55 = Integer.parseInt(s55);
rise1(ds54);
String snewTolerance = String.valueOf(getToleranceValue(ds55));
//Output:
tvWidResultValue.setText("" + s51 + s52 + s53 + "*10^" + ds54 + " Ohm");
tvWidToleranzValue.setText(""+ snewTolerance + " %");
}//onClick
});
}
}
public double rise1(double multiplikValue)
{
if (multiplikValue > -1)
{
if (multiplikValue < 7)
{
multiplikValue = multiplikValue++;
}
}
if (multiplikValue == 7)
{
multiplikValue = -1; //weil 10^-1 = 0.1
}
if (multiplikValue == 8)
{
multiplikValue = -2; //weil 10^-2 = 0.01
}
return multiplikValue;
}
public double getToleranceValue(double toleranz)
{
double newTolerance = 0;
if (toleranz == 0) //Spinnerposition
{
newTolerance = 1; //Toleranz-%-Wert
}
if (toleranz == 1 )
{
newTolerance = 2;
}
if (toleranz == 2 )
{
newTolerance = 0.5;
}
if (toleranz == 3 )
{
newTolerance = 0.25;
}
if (toleranz == 4 )
{
newTolerance = 0.1;
}
if (toleranz == 5 )
{
newTolerance = 5;
}
if (toleranz == 6 )
{
newTolerance = 10;
}
return newTolerance;
}
}
Thanks in advance! :)
Your variable names are very cryptic, but I think I see what is wrong. Try changing the checks in your btnCalcWid around, like this:
btnCalcwid.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if (rdbtn4rings.isChecked())
{
String s41 = String.valueOf(sp4Farbe1.getSelectedItemId()); //Farbe 1
String s42 = String.valueOf(sp4Farbe2.getSelectedItemId()); //Farbe 2
String s43 = String.valueOf(sp4Farbe3.getSelectedItemId()); //Multiplikator
String s44 = String.valueOf(sp4Farbe4.getSelectedItemId()); //Toleranz
int ds43 = Integer.parseInt(s43);
int ds44 = Integer.parseInt(s44);
rise1(ds43);
String snewTolerance = String.valueOf(getToleranceValue(ds44));
//Output:
tvWidResultValue.setText("" + s41 + s42 + "*10^" + ds43 + " Ohm");
tvWidToleranzValue.setText(""+ snewTolerance + " %");
}
else if (rdbtn5rings.isChecked())
{
String s51 = String.valueOf(sp5Farbe1.getSelectedItemId()); //Farbe 1
String s52 = String.valueOf(sp5Farbe2.getSelectedItemId()); //Farbe 2
String s53 = String.valueOf(sp5Farbe3.getSelectedItemId()); //Farbe 3
String s54 = String.valueOf(sp5Farbe4.getSelectedItemId()); //Multiplikator
String s55 = String.valueOf(sp5Farbe5.getSelectedItemId()); //Toleranz
int ds54 = Integer.parseInt(s54);
int ds55 = Integer.parseInt(s55);
rise1(ds54);
String snewTolerance = String.valueOf(getToleranceValue(ds55));
//Output:
tvWidResultValue.setText("" + s51 + s52 + s53 + "*10^" + ds54 + " Ohm");
tvWidToleranzValue.setText(""+ snewTolerance + " %");
}//else if
}//onClick
});//setOnClickListener