package com.example.palda.listviewappka;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
String [] auta = {"BMW", "Ford", "Audi", "Skoda", "Mazda"};//Seznam polozek
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,auta);
final ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
toustik(position);
}
});
}
public void toustik(int p){
TextView l1 = (TextView)findViewById(R.id.l1);
l1.setText(auta[p]);
//Toast.makeText(this, auta[p], Toast.LENGTH_SHORT).show();
}
public void doit(View view) {
EditText cks = (EditText)findViewById(R.id.e1);
EditText cjmeno = (EditText)findViewById(R.id.e2);
EditText cadresa = (EditText)findViewById(R.id.e3);
TextView cauto = (TextView)findViewById(R.id.l1);
String ks = cks.getText().toString();
String jmeno = cjmeno.getText().toString();
String adresa = cadresa.getText().toString();
String auto = cauto.getText().toString();
Toast.makeText(this, "Objednavka pro "+jmeno+" na adresu "+adresa+" je "+ks+"x "+auto, Toast.LENGTH_SHORT).show();
}
}