泰山医学院本科毕业设计(论文)
然后调用weibo接口request实现发布微博。
主要实现代码如下:
protected void onCreate(Bundle savedInstanceState) {
Intent ita = this.getIntent(); //获取已有的intent对象
Bundle bundle = ita.getExtras(); //获取intent里面的bundle对象 try { String tt = bundle.getString(\获取Bundle里面的字符串
lo.setText(tt); }
catch(Exception e){ } Timer timer = new Timer();
timer.schedule(new TimerTask(){ public void run() { InputMethodManager m = (InputMethodManager)sendcontent.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }, 1000);
int total = 140; num.setText(s);
info.setText(\发表新微博\
send.setOnClickListener(new OnClickListener(){ public void onClick(View v) { Weibo weibo = Weibo.getInstance(); String str = sendcontent.getText().toString(); update(weibo, str+\我在\ Toast.makeText(NewblogActivity.this, \发送成功!\
}
}); }
private String update(Weibo weibo, String status, String lon, String lat) throws WeiboException {
WeiboParameters bundle = new WeiboParameters(); bundle.add(\ if (!TextUtils.isEmpty(lon)) { bundle.add(\ }
if (!TextUtils.isEmpty(lat)) { bundle.add(\ }
12
泰山医学院本科毕业设计(论文)
String rlt = \
String url = Weibo.SERVER + \
rlt = weibo.request(this, url, bundle, Utility.HTTPMETHOD_POST, weibo.getAccessToken());
return rlt;
}
(三)查看博友微博(微博首页)模块
UI设计,在这个界面中,主要是一个ListView,在ListView中的每一个item中展示每一条微博。查看博友微博如图4-4所示:
图4-4手机新浪微博查看博友微博
这是在微博首页模块中的每一个微博的样式,最外面是一个水平方向的Linerlayout,用户头像右边是一个竖直方向的的Linerlayout, 然后依次是用户昵称,微博发布的时间,微博内容,微博发布方式,转发和评论数量。
在Android中,用列表控件来显示一组数据,比如显示从数据库查询出来的结果列表。Android将显示和数据分开来处理,在这二者中起到桥梁作用的就是adapter,示意图如图4-5所示:
13
泰山医学院本科毕业设计(论文)
图4-5adapter图
下面我们来详细描述一下我们自定义的adapter。
自己的adapter继承自BaseAdapter,需要实现其中几个方法: int getCount()
返回数据的数量,这里我们返回从新浪微博一次取回的用户自己和用户所关注的博友所发微博的数量。
Object getItem(int position)
从数据集合中返回参数position 指定的数据,我们这里返回第position 条微博。 String getId(int position)
返回指定位置的数据的ID,我们这里返回的是新浪提供的微博ID。 String getName(int position)
返回指定位置的数据的name,我们这里返回的是新浪提供的微博昵称。 View getView(int position, View convert, ViewGroup parent)
它的功能是将相应的数据放到一个子控件中,然后返回子控件,供父控件(列表控件)使用。第一个参数指定出数据的位置,第二个参数是要传给父控件的子控件,第三个参数是父控件。
首先,获得子控件:
private LayoutInflater inflater = null; inflater = LayoutInflater.from(context);
convert = inflater.inflate(R.layout.list_row, null); 然后设置需要显示的数据,具体实现代码如下:
holder.sources = (TextView)convert.findViewById(R.id.tvItemResource); holder.tvItemDate.setText(publishtime+\分钟前\holder.sources.setText(\来自:\items.get(position).get(\
holder.comme.setText(\评论 \items.get(position).get(\
holder.trans.setText(\转发 \items.get(position).get(\
convert.setTag(holder); 这样即可实现微博数据绑定。 效果图如图4-6所示:
14
泰山医学院本科毕业设计(论文)
图4-6微博展现
(四)查看我的微博列表
首先在个人资料页面中点击“微博”文字,通过添加点击事件将启动我的微博列表页面。
用户资料效果图如图4-7所示:
15
泰山医学院本科毕业设计(论文)
图4-7新浪微博查看我的微博列表
首先获取界面的控件对象并设置按钮的事件监听器,再通过getJSONObject方法获取用户的微博对象,在该方法中,通过该对象获取微博正文、用户昵称等信息,并以键值对的形式存放到map对象中,将该map对象添加到list列表中,实现微博列表的存储,获取到用户的微博列表后,设置界面ListView对象的adapter。
retu = (ImageButton)findViewById(R.id.re); lv = (ListView)findViewById(R.id.myweibqq); String s = getusertimeline(); List
listAdapter = new listviewAdapter3(this, list); lv.setAdapter(listAdapter);
public static List
List
JSONObject item = jsonArray.getJSONObject(i); // 得到每个对象 String text = item.getString(\获取对象对应的值
JSONObject userObj = new JSONObject(user); // 将其转化为JSONObject String name = userObj.getString(\ map.put(\
16
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库毕业论文终稿(4)在线全文阅读。
相关推荐: