Intents and activities in Android development

Day to fly

android string class void IT activity view

Abstract: The weekend masturbated several times the code, reluctant to throw, this as according to!

A couple of times over the weekend,

Reluctant to throw away,

Take this as a photo!


mainActivity.java


package com.tw.flag.ch08_memo; import android.content.Intent; 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.ListView; public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener { String[] aMemo = { "1. Can click edit notes ", "2. Long press can clear cheat", "3", "4", "5.", "6"}; ListView lv; ArrayAdapter<String> aa; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = (ListView)findViewById(R.id.listView); aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, aMemo); lv.setAdapter(aa); lv.setOnItemClickListener(this); lv.setOnItemLongClickListener(this); } @Override public void onItemClick(AdapterView<? > parent, View view, int position, long id) { Intent it = new Intent(this, Edit.class); It. PutExtra (" Memo ", aMemo[position]); startActivityForResult(it, position); } protected void onActivityResult(int requestCode, int resultCode, Intent it) {if (resultCode == RESULT_OK) {aMemo[requestCode] = it; aa.notifyDataSetChanged(); } } @Override public boolean onItemLongClick(AdapterView<? > parent, View view, int position, long id) { aMemo[position] = (position+1) + "."; aa.notifyDataSetChanged(); return true; }}Copy the code



package com.tw.flag.ch08_memo; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class Edit extends AppCompatActivity { TextView txv; EditText edt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit); Intent it = getIntent(); String s = it. GetStringExtra (" cheat "); txv = (TextView)findViewById(R.id.textView); txv.setText(s.substring(0, 2)); edt = (EditText)findViewById(R.id.editText); if (s.length() > 3) edt.setText(s.substring(3)); } public void onCancel(View v) { setResult(RESULT_CANCELED); finish(); } public void onSave(View v) { Intent it2 = new Intent(); PutExtra (" cheat ", txv.gettext () + "" + edt.gettext ()); setResult(RESULT_OK, it2); finish(); }}Copy the code






[email protected]

Use the cloud habitat community APP, comfortable ~

For details, please click
Review articles (0)

Related articles

The net friend comment on