2017-10-23 6 views
0

내 응용 프로그램은 데이터베이스에 데이터를 삽입하고이 데이터를 listView에 저장합니다. 사용자가 listview에서 항목을 클릭하면이 정보를 textView 형식에서 사용할 수 있습니다. 하지만 textView에서 회 전자 항목을 조정하는 방법은 무엇입니까?Spinner 항목을 TexView에 적용하는 방법

package cm.mavis.crud2; 

import android.app.ProgressDialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.os.AsyncTask; 
import android.support.v7.app.AlertDialog; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Spinner; 
import android.widget.TextView; 
import android.widget.Toast; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.util.HashMap; 


public class TampilPegawai extends AppCompatActivity implements View.OnClickListener{ 

private TextView editTextId; 
private Spinner spinneragence; 
private TextView editTextName; 
private TextView editTextDesg; 
private TextView editTextSalary; 

private Button buttonUpdate; 
private Button buttonDelete; 

private String id; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_tampil_pegawai); 

    Intent intent = getIntent(); 

    id = intent.getStringExtra(Configuration.EMP_ID); 

    spinneragence = (Spinner)findViewById(R.id.spinner1); 
    editTextName = (TextView) findViewById(R.id.editTextName); 
    editTextDesg = (TextView) findViewById(R.id.editTextDesg); 
    editTextSalary = (TextView) findViewById(R.id.editTextSalary); 

    buttonUpdate = (Button) findViewById(R.id.buttonUpdate); 
    buttonDelete = (Button) findViewById(R.id.buttonDelete); 

    buttonUpdate.setOnClickListener(this); 
    buttonDelete.setOnClickListener(this); 

    getEmployee(); 
} 

private void getEmployee(){ 
    class GetEmployee extends AsyncTask<Void,Void,String>{ 
     ProgressDialog loading; 
     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      loading = ProgressDialog.show(TampilPegawai.this,"Fetching...","Patientez...",false,false); 
     } 

     @Override 
     protected void onPostExecute(String s) { 
      super.onPostExecute(s); 
      loading.dismiss(); 
      showEmployee(s); 
     } 

     @Override 
     protected String doInBackground(Void... params) { 
      RequestHandler rh = new RequestHandler(); 
      String s = rh.sendGetRequestParam(Configuration.URL_GET_EMP,id); 
      return s; 
     } 
    } 
    GetEmployee ge = new GetEmployee(); 
    ge.execute(); 
} 

private void showEmployee(String json){ 
    try { 
     JSONObject jsonObject = new JSONObject(json); 
     JSONArray result = jsonObject.getJSONArray(Configuration.TAG_JSON_ARRAY); 
     JSONObject c = result.getJSONObject(0); 
     String agence = c.getString(Configuration.TAG_AGENCE); 
     String name = c.getString(Configuration.TAG_NOM); 
     String desg = c.getString(Configuration.TAG_POSITION); 
     String sal = c.getString(Configuration.TAG_SALAIRE); 

     spinneragence. 
     editTextName.setText(name); 
     editTextDesg.setText(desg); 
     editTextSalary.setText(sal); 

    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
} 


private void updateEmployee(){ 
    final String agence = spinneragence.getSelectedItem().toString(); 
    final String name = editTextName.getText().toString().trim(); 
    final String desg = editTextDesg.getText().toString().trim(); 
    final String salary = editTextSalary.getText().toString().trim(); 

    class UpdateEmployee extends AsyncTask<Void,Void,String>{ 
     ProgressDialog loading; 
     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      loading = ProgressDialog.show(TampilPegawai.this,"Mise a jour...","Patientez...",false,false); 
     } 

     @Override 
     protected void onPostExecute(String s) { 
      super.onPostExecute(s); 
      loading.dismiss(); 
      Toast.makeText(TampilPegawai.this,s,Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     protected String doInBackground(Void... params) { 
      HashMap<String,String> hashMap = new HashMap<>(); 
      hashMap.put(Configuration.KEY_EMP_ID,id); 
      hashMap.put(Configuration.KEY_EMP_NOM,name); 
      hashMap.put(Configuration.KEY_EMP_AGENCE,agence); 
      hashMap.put(Configuration.KEY_EMP_POSITION,desg); 
      hashMap.put(Configuration.KEY_EMP_SALAIRE,salary); 

      RequestHandler rh = new RequestHandler(); 

      String s = rh.sendPostRequest(Configuration.URL_UPDATE_EMP,hashMap); 

      return s; 
     } 
    } 

    UpdateEmployee ue = new UpdateEmployee(); 
    ue.execute(); 
} 

private void deleteEmployee(){ 
    class DeleteEmployee extends AsyncTask<Void,Void,String> { 
     ProgressDialog loading; 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
      loading = ProgressDialog.show(TampilPegawai.this, "Mise a jour...", "Patientez...", false, false); 
     } 

     @Override 
     protected void onPostExecute(String s) { 
      super.onPostExecute(s); 
      loading.dismiss(); 
      Toast.makeText(TampilPegawai.this, s, Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     protected String doInBackground(Void... params) { 
      RequestHandler rh = new RequestHandler(); 
      String s = rh.sendGetRequestParam(Configuration.URL_DELETE_EMP, id); 
      return s; 
     } 
    } 

    DeleteEmployee de = new DeleteEmployee(); 
    de.execute(); 
} 

private void confirmDeleteEmployee(){ 
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 
    alertDialogBuilder.setMessage("Voulez vous supprimer ce salarié?"); 

    alertDialogBuilder.setPositiveButton("Oui", 
      new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface arg0, int arg1) { 
        deleteEmployee(); 
        startActivity(new Intent(TampilPegawai.this,TampilSemuaPgw.class)); 
       } 
      }); 

    alertDialogBuilder.setNegativeButton("Non", 
      new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface arg0, int arg1) { 

       } 
      }); 

    AlertDialog alertDialog = alertDialogBuilder.create(); 
    alertDialog.show(); 
} 

@Override 
public void onClick(View v) { 
    if(v == buttonUpdate){ 
     updateEmployee(); 
    } 

    if(v == buttonDelete){ 
     confirmDeleteEmployee(); 
    } 
} 
} 

이 코드를 수정하는 데 도움을주십시오. 스피너 선택은 데이터베이스에 올바르게 삽입되지만 textView 형식으로 표시하는 방법은 무엇입니까?

답변

0

Android에서는 UI 요소를 스타일이 아닌 것으로 스타일을 지정할 수 있습니다. 예를 들어, 다음

<style name="SpinnerText" parent="android:Widget.TextView"/> 

,

<Spinner style="@style/SpinnerText" .../> 

당신은 아마 당신이 찾고있는 정확하게 얻을 조정할해야합니다,하지만 당신은 아이디어를 얻을.

+0

자바 코드가 내 코드를 showemployee() 함수에서 봐 주어야한다. –