短信主要界面:会话列表,会话详情,新建短信。
联系人主要界面:联系人列表,编辑联系人。
创建首页。首页由TabActivity表现。
在Android4.1中,TabActivity处于保护状态。
The type TabActivity is deprecated
没关系,继续使用。
[Accessibility] Missing contentDescription attribute on image
将会话分为两种:单一收件人会话。多个收件人会话。
在XXXAdapter.getView中,使用converView.setTag(Object)和getTag()。
得到会话时间。昨天,今天,等等。
创建一个Application子类TxrjApplication
android.app.Application
Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's <application> tag, which will cause that class to be instantiated for you when the process for your application/package is created.
There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a android.content.Context which internally uses Context.getApplicationContext() when first constructing the singleton.
要点:用来维护全局应用状态。在AndroidManifest.xml文件中<application>标签中指定名字,然后你可以提供Application的实现。当应用包的进程创建时,Application会被实例化。
<uses-permission> tag appears after <application> tag
<uses-permission>标签必须放在<application>之前。
使用AsyncTask来获取会话列表。
去掉Activity的标题栏两种办法
1.在代码中设置
requestWindowFeature(Window.FEATURE_NO_TITLE);
2.在AndroidManifest.xml文件中<application>标签中设置
android:theme="@android:style/Theme.NoTitleBar"
参考链接:
添加一条草稿时出现空指针异常
07-05 14:30:55.966: E/AndroidRuntime(11857): FATAL EXCEPTION: main
07-05 14:30:55.966: E/AndroidRuntime(11857): java.lang.NullPointerException
07-05 14:30:55.966: E/AndroidRuntime(11857): at com.txrj.sms.common.TxrjUtils.getString(TxrjUtils.java:20)
07-05 14:30:55.966: E/AndroidRuntime(11857): at com.txrj.sms.adapter.ConversationListAdapter.getView(ConversationListAdapter.java:102)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.AbsListView.obtainView(AbsListView.java:2485)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.fillDown(ListView.java:678)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.fillFromTop(ListView.java:738)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.layoutChildren(ListView.java:1631)
已经fix:
holder.draft.setText("["+TxrjUtils.getString(mContext, R.string.sms_draft)+"]");
此语句中第一个实参mContext为空,没有在构造方法中赋值导致。
会话列表加载有点点慢!
ListView的Item点击事件实现步骤:
1. ListView.setOnItemClickListener
2. implements AdapterView.OnItemClickListenr
3. (override) onItemClick(AdapterView parent, View view, int position, long id)
点击APP图标显示会话列表时出现异常
07-06 10:40:46.015: E/AndroidRuntime(10057): FATAL EXCEPTION: main
07-06 10:40:46.015: E/AndroidRuntime(10057): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txrj.sms/com.txrj.sms.activity.ConversationListActivity}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.os.Looper.loop(Looper.java:137)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.main(ActivityThread.java:4517)
mCreateMsgBtn = (Button) findViewById(R.id.create_message);
将(Button)改成(ImageButton)
点击会话列表中的一个item出现异常1
07-06 10:47:31.150: E/AndroidRuntime(10967): FATAL EXCEPTION: main
07-06 10:47:31.150: E/AndroidRuntime(10967): android.content.ActivityNotFoundException: No Activity found to handle Intent { (has extras) }
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1388)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Activity.startActivityForResult(Activity.java:3195)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Activity.startActivity(Activity.java:3302)
07-06 10:47:31.150: E/AndroidRuntime(10967): at com.txrj.sms.activity.ConversationListActivity.onItemClick(ConversationListActivity.java:67)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AbsListView.performItemClick(AbsListView.java:1427)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3057)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AbsListView$1.run(AbsListView.java:3970)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.os.Handler.handleCallback(Handler.java:605)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.os.Looper.loop(Looper.java:137)
添加语句:it.setClass(mContext, MessageListActivity.class);
点击会话列表中的一个Item出现异常2
07-06 10:51:37.861: E/AndroidRuntime(11331): FATAL EXCEPTION: main
07-06 10:51:37.861: E/AndroidRuntime(11331): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txrj.sms/com.txrj.sms.activity.MessageListActivity}: android.view.InflateException: Binary XML file line #70: Error inflating class EditView
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.os.Looper.loop(Looper.java:137)
标签名字出错了,将(EditView)改成(EditText)。
进入MessageListActivity中出现异常1
07-06 10:57:03.539: E/AndroidRuntime(11815): FATAL EXCEPTION: main
07-06 10:57:03.539: E/AndroidRuntime(11815): java.lang.NullPointerException
07-06 10:57:03.539: E/AndroidRuntime(11815): at com.txrj.sms.activity.MessageListActivity$LoadMessagesTask.onPostExecute(MessageListActivity.java:78)
07-06 10:57:03.539: E/AndroidRuntime(11815): at com.txrj.sms.activity.MessageListActivity$LoadMessagesTask.onPostExecute(MessageListActivity.java:1)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.AsyncTask.finish(AsyncTask.java:602)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.AsyncTask.access$600(AsyncTask.java:156)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.Looper.loop(Looper.java:137)
mListView = (ListView) findViewById(R.id.threads_list);
将(threads_list)改成(message_list)
进入MessageListActivity中出现异常2
07-06 11:11:20.795: E/AndroidRuntime(12676): FATAL EXCEPTION: main
07-06 11:11:20.795: E/AndroidRuntime(12676): android.view.InflateException: Binary XML file line #42: Error inflating class tyu.common.ui.component.TyuTextView
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-06 11:11:20.795: E/AndroidRuntime(12676): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:90)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.widget.AbsListView.obtainView(AbsListView.java:2485)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.widget.ListView.makeAndAddView(ListView.java:1780)
将(tyu.common.ui.component.TyuTextView)改成(TextView)
在MessageListActivity中上下滑动时出现异常1
07-06 11:14:27.728: E/AndroidRuntime(13371): FATAL EXCEPTION: main
07-06 11:14:27.728: E/AndroidRuntime(13371): java.lang.NullPointerException
07-06 11:14:27.728: E/AndroidRuntime(13371): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:99)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.AbsListView.obtainView(AbsListView.java:2464)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.ListView.fillUp(ListView.java:711)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.ListView.fillGap(ListView.java:651)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5877)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5018)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.os.Handler.handleCallback(Handler.java:605)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.os.Looper.loop(Looper.java:137)
添加语句:convertView.setTag(holder);
在MessageListActivity中的信息列表ListView中,send的信息变成receiver的信息了。
删除掉TrxjMessage类中的status字段。
使用type字段即可,type说明如下:
public interface TextBasedSmsColumns {
/**
* The type of the message
* <P>Type: INTEGER</P>
*/
public static final String TYPE = "type";
public static final int MESSAGE_TYPE_ALL = 0;
public static final int MESSAGE_TYPE_INBOX = 1;
public static final int MESSAGE_TYPE_SENT = 2;
public static final int MESSAGE_TYPE_DRAFT = 3;
public static final int MESSAGE_TYPE_OUTBOX = 4;
public static final int MESSAGE_TYPE_FAILED = 5; // for failed outgoing messages
public static final int MESSAGE_TYPE_QUEUED = 6; // for messages to send later
在MessageListActivity中上下滑动时出现异常2
07-06 11:32:03.428: E/AndroidRuntime(14253): FATAL EXCEPTION: main
07-06 11:32:03.428: E/AndroidRuntime(14253): java.lang.NullPointerException
07-06 11:32:03.428: E/AndroidRuntime(14253): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:109)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.AbsListView.obtainView(AbsListView.java:2464)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.ListView.fillUp(ListView.java:711)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.ListView.fillGap(ListView.java:651)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5877)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5018)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.os.Handler.handleCallback(Handler.java:605)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.os.Looper.loop(Looper.java:137)
使用if(type == Telephony.Sms.MESSAGE_TYPE_INBOX){…} else {…}
去掉TrxjMessage.SEND, TrxjMessage.RECEIVE
使用convertView.setTag(viewHolder), convertView.getTag(); 需要注意 ListView中的每个item都有相同的结构和元素。
目前,receive的信息没有status和progressBar,send的信息有。
如果以receiver的layout文件构建convertView,当遇到send的view时,也没有status和progressBar。
就会出现空指针异常。
07-06 12:02:53.102: E/AndroidRuntime(18854): FATAL EXCEPTION: main
07-06 12:02:53.102: E/AndroidRuntime(18854): java.lang.NullPointerException
07-06 12:02:53.102: E/AndroidRuntime(18854): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:112)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.AbsListView.obtainView(AbsListView.java:2464)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.ListView.fillUp(ListView.java:711)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.ListView.fillGap(ListView.java:651)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5877)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5018)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.os.Handler.handleCallback(Handler.java:605)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.os.Looper.loop(Looper.java:137)
holder.status = (TextView) convertView.findViewById(R.id.status);
将(R.id.send_status)改成(R.id.status)