Javaファイル変換スピナー値
public class CreateScreen extends AppCompatActivity {
EditText e1,e2,e3,e4,e5,e6,e7;
Button b1,b2;
Spinner s1,s2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.activity_create_screen);
final Intent i = getIntent();
String vno = i.getStringExtra("vno");
String com = i.getStringExtra("com");
e1=(EditText)findViewById(R.id.editText8);
e2=(EditText)findViewById(R.id.editText9);
e3=(EditText)findViewById(R.id.editText10);
e4=(EditText)findViewById(R.id.editText11);
e5=(EditText)findViewById(R.id.editText12);
e6=(EditText)findViewById(R.id.editText13);
e7=(EditText)findViewById(R.id.editText14);
e1.setText(vno);
e2.setText(com);
s1=(Spinner)findViewById(R.id.spinner);
String[] items = new String[]{"RAW MATERIAL", "FINISHED MATERIAL", "SEMI FINISHED MATERIAL"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items);
s1.setAdapter(adapter);
final String matgrp = adapter.toString();
s2=(Spinner)findViewById(R.id.spinner2);
String[] item = new String[]{"INR", "USD", "MYR","JPY", "SGD"};
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, item);
s2.setAdapter(adapter1);
final String currency = adapter1.toString();
b1=(Button)findViewById(R.id.save);
b2=(Button)findViewById(R.id.home);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(CreateScreen.this,MaterialMenu.class);
startActivity(i);
}
});
b1.setOnClickListener(new View.OnClickListener() {
InputStream is =null;
String result1 =null;
@Override
public void onClick(View v) {
String a = e1.getText().toString();
String b = e2.getText().toString();
String c = e3.getText().toString();
String d = e4.getText().toString();
String z = e5.getText().toString();
String f = e6.getText().toString();
String g = e7.getText().toString();
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("materialnumber", a));
nameValuePairs.add(new BasicNameValuePair("companycode", b));
nameValuePairs.add(new BasicNameValuePair("desc", c));
nameValuePairs.add(new BasicNameValuePair("mattype", matgrp));
nameValuePairs.add(new BasicNameValuePair("matgroup", d));
nameValuePairs.add(new BasicNameValuePair("baseunit", z));
nameValuePairs.add(new BasicNameValuePair("priceunit", f));
nameValuePairs.add(new BasicNameValuePair("orderunit", g));
nameValuePairs.add(new BasicNameValuePair("curr",currency));
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://10.0.2.2/android/create.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
android.util.Log.e("log_tag", "connection success ");
} catch (Exception e) {
android.util.Log.e("log_tag", "Error in http connection " + e.toString());
Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_SHORT).show();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result1 = sb.toString();
} catch (Exception e) {
android.util.Log.e("log_tag", "Error converting result " + e.toString());
}
try
{
JSONObject object = new JSONObject(result1);
String w = object.getString("re");
if(w.equals("Material Created successfully"))
{
Toast.makeText(getApplicationContext(), w, Toast.LENGTH_SHORT).show();
Intent i = new Intent(CreateScreen.this, Menu.class);
startActivity(i);
}
else
{
Toast.makeText(getApplicationContext(), w, Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
Log.e("log_tag", "Error parsing data "+e.toString());
Toast.makeText(getApplicationContext(), "JsonArray failed to load", Toast.LENGTH_SHORT).show();
}
}
});
}
はlogcat
値は、私が書き換えする必要がありますどのように文字列
に変換することはできませんこのコードはスピナー値をJsonObjectとPHPで使用される文字列に変換しますか?ここ
完全なログを投稿しないでください。 :) –
スピナーの値はどこに渡したいですか? –
誰でも私に作業コードをチェックして更新できますか? – Raahul