Я новичок в Android и отдых Template.I разработали андроид экрана и отображения данных в формате JSON с помощью Rest шаблона GET метод на мой screen.My следующий шаг, чтобы обновить некоторые поля, такие как имя редактирования, и добавьте недостающие вещи и сохраните их обратно.Отдых Шаблон метод PUT В Android
открытый класс MyPreferences extends AppCompatActivity { TextView tv; private Listcp = new ArrayList <>();
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_preferences); Resources resources = getResources(); Log.d("Consumer pojo", "onCreate:"); new HttpRequestTask().execute(); } private class HttpRequestTask extends AsyncTask<Void, Void, ConsumerProfile>{ @Override protected ConsumerProfile doInBackground(Void... params) { try { final String url = "http://192.168.1.213:9001/consumer/local/"+LoginFragment.CONSUMEROBJECT.getId(); RestTemplate restTemplate = new RestTemplate(); ConsumerProfile cp = restTemplate.getForObject(url, ConsumerProfile.class); return cp; }catch (Exception e){ Log.e("MainActivity", e.getMessage(),e); } return null; } @Override protected void onPostExecute(ConsumerProfile cp){ super.onPostExecute(cp); Log.d("cppppppppppppppppppppp", "onPostExecute: " + cp.getId()); TextView fname=(TextView)findViewById(R.id.editfname); TextView mname=(TextView)findViewById(R.id.editmname); TextView lname=(TextView)findViewById(R.id.editlname); TextView nname=(TextView)findViewById(R.id.editnname); TextView dob=(TextView)findViewById(R.id.editdob); TextView status=(TextView)findViewById(R.id.editstatus); TextView homeAddress=(TextView)findViewById(R.id.edithomeAddr); TextView workAddress=(TextView)findViewById(R.id.editworkAddr); TextView income=(TextView)findViewById(R.id.editincome); fname.setText(cp.getFirstName()); mname.setText(cp.getMiddleName()); lname.setText(cp.getLastName()); nname.setText(cp.getNickName()); dob.setText(cp.getDob()); status.setText(cp.getStatus()); homeAddress.setText(cp.getHomeAddress()); workAddress.setText(cp.getWorkAddress()); income.setText(cp.getIncome());
Это то, что я сделал до сих пор.
Этот код предназначен для метода Get.
- Он отобразит экран, как на изображении.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"><![CDATA[
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
]]>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/scrollView2" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <TextView
android:layout_width="wrap_content"
android:scrollbars="vertical"
android:layout_height="wrap_content"
android:text="firstName"/>
<EditText
android:id="@+id/editfname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="middleName"/>
<EditText
android:id="@+id/editmname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lastName"/>
<EditText
android:id="@+id/editlname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="nickName"/>
<EditText
android:id="@+id/editnname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dob"/>
<EditText
android:id="@+id/editdob"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"/>
<EditText
android:id="@+id/editstatus"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="homeAddress"/>
<EditText
android:id="@+id/edithomeAddr"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="workAddress"/>
<EditText
android:id="@+id/editworkAddr"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="income"/>
<EditText
android:id="@+id/editincome"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update Preferences"
android:id="@+id/button"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</ScrollView>
</LinearLayout>
- Это мой макет.
- Фактически, что я пытаюсь сделать, это получить информацию о пользователе и изменить информацию и сохранить обратно в ту же конечную точку.
- Когда пользователь выбирает кнопку «Обновить», тогда он отобразит обновленный экран.
- Любая помощь с оценкой.
- Любой Предоставить код для этого.
- Благодарен им.
Проведя целый день, наконец, я нашел решение ............. – rakesh