編輯:關於Android編程
寫了一個DEMO:短信選擇聯系人的數據傳遞
主activity:
import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.EditText; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View c){ //跳轉至選擇聯系人Activity Intent intent = new Intent(this, ContactActivity.class); // startActivity(intent); //用這個api啟動的Activity,在銷毀時,系統會回調onActivityResult startActivityForResult(intent, 10); } public void click2(View v){ //跳轉至選擇快捷回復的Activity Intent intent = new Intent(this, CallbackActivity.class); startActivityForResult(intent, 20); } //如果有Activity在銷毀時返回了數據,那麼就會調用此方法來接收數據 //requestCode:用來區分數據來自於哪一個Activity //resultCode:用來區分返回的數據是什麼類型的 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); String name = data.getStringExtra("name"); if(requestCode == 10){ EditText et = (EditText)findViewById(R.id.et); et.setText(name); } else if(requestCode == 20){ EditText et_content = (EditText)findViewById(R.id.et_content); et_content.setText(name); } } }聯系人activity:
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class ContactActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_contact); ListView lv = (ListView) findViewById(R.id.lv); final String[] objects = new String[]{ "小志", "逼哥", "世界級XXX", "國服第一" }; lv.setAdapter(new ArrayAdapter(this, R.layout.item_listview, R.id.tv, objects)); //給listview設置條目的點擊偵聽 lv.setOnItemClickListener(new OnItemClickListener() { //當某個條目被點擊時,此方法調用 @Override public void onItemClick(AdapterView parent, View view, int position, long id) { //Activity返回時傳遞數據,也是通過意圖對象 Intent data = new Intent(); //把要傳遞的數據封裝至意圖對象中 data.putExtra("name", objects[position]); //當前Activity銷毀時,data這個意圖就會傳遞給啟動當前Activity的那個Activity setResult(1, data); //銷毀當前Activity finish(); } }); } @Override public void onBackPressed() { // TODO Auto-generated method stub super.onBackPressed(); } }
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class CallbackActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_contact); ListView lv = (ListView) findViewById(R.id.lv); final String[] objects = new String[]{ "免談,沒戲,滾犢子", "媳婦我錯了,求原諒", "老子才是一家之主" }; lv.setAdapter(new ArrayAdapter(this, R.layout.item_listview, R.id.tv, objects)); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Intent data = new Intent(); data.putExtra("name", objects[position]); setResult(2, data); finish(); } }); } }
網上找的圓形imageview自定義控件:‘package com.wangll.widget;import android.content.Context;
這就是開源的好處,通過Github、各大論壇和技術博客,你會發現很多對你有用的資源。對於做技術的同學來說,深入研究一門技術很重要,但是適當的擴展自己的視野,了解他人的一些
前言相信很多朋友在開發中都會遇到圖片上傳的情況,尤其是多圖上傳,最經典的莫過於微信的圖片選擇了。所有很多情況下會使用到多圖選擇,所以就有了這篇文章,今天抽點時間寫了個控件
ViewPager這個小demo實現的是可以左右循環滑動圖片,下面帶索引,滑到最後一頁在往右滑動就要第一頁,第一頁往左滑動就到最後一頁,先上效果圖:1、首先看一些layo