首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使微调控制器项适应TexView

如何使微调控制器项适应TexView
EN

Stack Overflow用户
提问于 2017-10-24 04:51:45
回答 1查看 45关注 0票数 0

我的应用程序在数据库中插入数据,并将这些数据保存在listView中。当用户单击listview中的项目时,此信息可用于textView表单。但是如何在textView中调整微调项呢?

代码语言:javascript
运行
复制
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();
    }
}
} 

请帮我纠正这个code.the旋转器选择是正确地插入到数据库中,但是如何在textView表单中显示?

EN

回答 1

Stack Overflow用户

发布于 2017-10-24 04:57:00

在Android中,您可以将UI元素的样式设置为它们不是的样式。例如,

代码语言:javascript
运行
复制
<style name="SpinnerText" parent="android:Widget.TextView"/>

然后,

代码语言:javascript
运行
复制
<Spinner style="@style/SpinnerText" .../>

您可能必须对其进行调整,才能获得您正在寻找的内容,但您已经明白了这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46898316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档