(droid分享)新浪微博开发系列【十三】之微博的评论转发-程序员宅基地

技术标签: layout  button  dialog  null  新浪微博  android  

此部分为进行微博的评论,由于转发也在此activity中进行,所以就直贴出评论的微博界面,同时此部分也是微博开发所有的activity开发的终结篇,后面我会贴上所有的工具类。好了,贴代码,在此说明一下,可能代码里调用一些方法在本篇中没有,但是全部在我的代码里,也不要索取图片,要看全部代码的请移步http://blog.csdn.net/gaojin1991/article/details/8022213

<?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:background="#00ffffff"
    android:orientation="vertical" >


    <RelativeLayout
        android:id="@+id/repostandcommentTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#BB768e95" >


        <!-- android:background="@drawable/bg_title" -->


        <ImageButton
            android:id="@+id/repostbtnClose"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/title_back"
            android:contentDescription="@string/contnetdescription" />


        <Button
            android:id="@+id/repostandcommentbtnSend"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginRight="6dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/bg_btn"
            android:paddingBottom="2dp"
            android:text="@string/repostandcommentActivity_send"
            android:textColor="#fff"
            android:textSize="12sp" />


        <TextView
            android:id="@+id/repostandcommenttype"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/repostandcommentbtnSend"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:textColor="#000"
            android:textSize="20sp"
            android:textStyle="bold" />
    </RelativeLayout>


    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/bg_activitycontent" >


        <LinearLayout
            android:id="@+id/repostandcommentllImage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#00ffffff"
            android:orientation="vertical" >


            <RelativeLayout
                android:id="@+id/repostandcommentTotal"
                android:layout_width="fill_parent"
                android:layout_height="50dp" >


                <LinearLayout
                    android:id="@+id/repostandcommentll_text_limit_unit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="false"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:background="@drawable/bg_delwords"
                    android:clickable="true"
                    android:focusable="true"
                    android:gravity="center" >


                    <TextView
                        android:id="@+id/repostandcommenttv_text_limit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="5dp"
                        android:text="@string/repostandcommentActivity_contnetmaxcount"
                        android:textColor="#333" />


                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@string/contnetdescription"
                        android:src="@drawable/icon_delwords" />
                </LinearLayout>
            </RelativeLayout>            


            <RelativeLayout
                android:id="@+id/repostandcommenttoolbarlayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:orientation="horizontal" >


                <LinearLayout
                    android:id="@+id/repostandcommentinsertpiclayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                </LinearLayout>


                <LinearLayout
                    android:id="@+id/repostandcommentinsertatlayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:orientation="vertical" >
                </LinearLayout>


                <LinearLayout
                    android:id="@+id/repostandcommentinsertfacelayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                </LinearLayout>


                
            </RelativeLayout>
        </LinearLayout>


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/repostandcommentllImage"
            android:layout_alignParentTop="true"
            android:layout_margin="3dp"
            android:background="#00ffffff"
            android:orientation="vertical" >


            <EditText
                android:id="@+id/repostandcommentetEdit"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_margin="3dp"
                android:background="@null"
                android:gravity="top|left"
                android:imeOptions="actionDone"
                android:inputType="textMultiLine"
                android:isScrollContainer="true"
                android:maxLength="140"
                android:singleLine="false" />
        </LinearLayout>
    </RelativeLayout>


</LinearLayout>



package com.czu.sinaweibo;



import java.io.IOException;
import java.net.MalformedURLException;


import com.czu.constdata.ConstDataSinaAPI;
import com.czu.weiboHandler.WeiBoInfoSender;
import com.weibo.android.R;
import com.weibo.net.AsyncWeiboRunner.RequestListener;
import com.weibo.net.Weibo;
import com.weibo.net.WeiboException;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


public class RepostAndCommentActivity extends Activity implements
RequestListener {
/* 标题内容 */
private TextView activityTitle = null;
/* 返回按钮 */
private ImageButton btnClose = null;


/* 发送按钮 */
private Button btnSend = null;


/* 微博内容 */
private EditText contentEditText = null;


/* 当前字数 */
private TextView textLimitTextView = null;


/* 要转发的微博ID */
private String weiBoId = null;


/* 要转发的微博内容 */
String repostorcomment = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.repostandcomment_activity);


activityTitle = (TextView) this.findViewById(R.id.repostandcommenttype);
/* 微博转发 */
if (getIntent().getFlags() == 0) {
weiBoId = getIntent().getExtras().getString("repostID");
activityTitle.setText("转发微博");
} else {
weiBoId = getIntent().getExtras().getString("commentID");
activityTitle.setText("评论微博");
}


/* 得到字数限制对象 */
textLimitTextView = (TextView) this
.findViewById(R.id.repostandcommenttv_text_limit);


contentEditText = (EditText) this.findViewById(R.id.repostandcommentetEdit);
contentEditText.addTextChangedListener(new TextWatcher() {


@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
int currentlength = ConstDataSinaAPI.WEIBO_MAX_LENGTH
- contentEditText.getText().toString().length();
textLimitTextView.setText(String.valueOf(currentlength));


}


@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub


}


@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub


}
});


/* 获取btnClose对象 */
btnClose = (ImageButton) this.findViewById(R.id.repostbtnClose);
/* 对btnClose按钮进行监听,关闭当前Activity */
btnClose.setOnClickListener(new ImageButton.OnClickListener() {


@Override
public void onClick(View v) {
if (contentEditText.getText().toString().isEmpty()) {
finish();
} else {
Dialog dialog = new AlertDialog.Builder(
RepostAndCommentActivity.this)
.setTitle(
R.string.repostandcommentActivity_attention)
.setMessage(
R.string.repostandcommentActivity_exitattention)
.setPositiveButton(
R.string.repostandcommentActivity_ok,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
finish();
}
})
.setNegativeButton(
R.string.repostandcommentActivity_cancel,
null).create();
dialog.show();
}


}


});


btnSend = (Button) this.findViewById(R.id.repostandcommentbtnSend);


btnSend.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {


{


Weibo weibo = Weibo.getInstance();
WeiBoInfoSender weiBoInfoSender = new WeiBoInfoSender(
RepostAndCommentActivity.this);


try {

String title=activityTitle.getText().toString();

/*没有输入内容*/
if (contentEditText.getText().toString().isEmpty()) {
/*默认为空*/
if(title.equals("转发微博")){
repostorcomment="转发微博";
weiBoInfoSender.repost(weibo, Weibo.getAppKey(),repostorcomment, weiBoId, "", "");
}
else if (title.equals("评论微博")) {
Toast.makeText(RepostAndCommentActivity.this,R.string.repostandcommentActivity_sendattention , Toast.LENGTH_SHORT).show();
}
}//输入了内容
else {
repostorcomment=contentEditText.getText().toString();
if(title.equals("转发微博")){
weiBoInfoSender.repost(weibo, Weibo.getAppKey(),repostorcomment, weiBoId, "", "");
}
else if (title.equals("评论微博")){
weiBoInfoSender.create(weibo,Weibo.getAppKey(),repostorcomment, weiBoId, "","");
}
}


} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WeiboException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}
});


LinearLayout linearLayout = (LinearLayout) this
.findViewById(R.id.repostandcommentll_text_limit_unit);
linearLayout.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
if (!contentEditText.getText().toString().isEmpty()) {
Dialog dialog = new AlertDialog.Builder(
RepostAndCommentActivity.this)
.setTitle(
R.string.repostandcommentActivity_attention)
.setMessage(
R.string.repostandcommentActivity_delall)
.setPositiveButton(
R.string.repostandcommentActivity_ok,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
contentEditText.setText("");
}
})
.setNegativeButton(
R.string.repostandcommentActivity_cancel,
null).create();
dialog.show();
}


}
});


}


@Override
public void onComplete(String response) {
runOnUiThread(new Runnable() {


@Override
public void run() {
Toast.makeText(RepostAndCommentActivity.this,
R.string.repostandcommentActivity_send_sucess,
Toast.LENGTH_LONG).show();
}
});


this.finish();


}


@Override
public void onIOException(IOException e) {
// TODO Auto-generated method stub


}


@Override
public void onError(final WeiboException e) {
runOnUiThread(new Runnable() {


@Override
public void run() {
Toast.makeText(
RepostAndCommentActivity.this,
String.format(
RepostAndCommentActivity.this
.getString(R.string.repostandcommentActivity_send_failed)
+ ":%s", e.getMessage()),
Toast.LENGTH_LONG).show();
}
});


}


}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/gaojin1991/article/details/8022369

智能推荐

【C++】34. gflags中的 --flagfile= 用法_gflags --flagfile-程序员宅基地

文章浏览阅读1.8k次。如果要把代码中的变量做成可通过配置文件进行配置的,可以使用gflag来实现。如,想要通过代码运行FLAGS_apple_nums可以这样定义:DECLARE_int32(apple_nums); //定义在 .h文件---------------------------------------------------------DEFINE_int32(apple_nums, 0, "num of apple"); //定义在 .cc文件对于gflags中的--flagfile用法,不管后面_gflags --flagfile

《MySQL从0到1:数据查询自给自足》_mysql 0-1 查询-程序员宅基地

文章浏览阅读555次。我准备写一系列文章,给非技术类的同学介绍下生物系毕业的我,学习mysql的过程,分享给大家一些基本语法和注意事项,完全以应用为主,计算机科班出身和大牛们请绕过~《MySQL从0到1》 从没有听过MySQL的名字,到与MySQL相遇;从只听过MySQL的名字,到与MySQL相识;从对MySQL有所了解和应用,到与MySQL相熟;个人从一个Excel都不怎么会的菜鸟,到每天使用MySQL提取数据有1年_mysql 0-1 查询

python爬虫-python爬虫到底可以爬些什么,有啥作用;_爬虫爬的数据一般都有什么作用-程序员宅基地

文章浏览阅读651次。本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理以下文章来源于腾讯云 作者:用户2769421( 想要学习Python?Python学习交流群:1039649593,满足你的需求,资料都已经上传群文件流,可以自行下载!还有海量最新2020python学习资料。 )Python爬虫可以爬取的东西有很多,Python爬虫怎么学?简单的分析下:如果你仔细观察,就不难发现,懂爬虫、学习爬虫的人越来越多,一方面,互联网可以获取的数据越来越多_爬虫爬的数据一般都有什么作用

Flutter 多语言自动化本地化生成器_flutter 生成多语言命令-程序员宅基地

文章浏览阅读1.2k次,点赞22次,收藏22次。简体中文 |这是一个为Flutter设计的插件,通过从Excel表格提取的CSV文件自动生成Dart本地化文件,以简化应用程序本地化的流程。这个工具通过自动化创建多语言资源文件,简化了开发人员和翻译人员的工作流程。_flutter 生成多语言命令

python免费安装安装教程,python免安装版本怎么用-程序员宅基地

文章浏览阅读242次,点赞5次,收藏4次。执行完成python根目录会自动创建Lib和Scripts文件夹, 需要将 Lib\site_packages 这一段路径写到 python*._pth中(或者删除#号),或者不修改文件,将此文件夹中的 pip文件夹拷贝到 python 解压的路径中(python.exe 所在路径)。清华源安装some-package:python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package。

织梦DedeCMS列表“加载更多”“无限下拉”Ajax加载使用方法-程序员宅基地

文章浏览阅读397次。记录一次项目经历,需要在DEDECMS中用到无限下拉替换点击分页功能,分享下,记录点滴,需要的可以共同交流!Infinite Ajax Scroll简称ias,无限的ajax滚动,是一款jQuery滚动ajax分页插件,当页面滚动到容器可见部分将自动异步加载数据。下面先来看看效果。无限下拉效果点击加载更多效果插件说明炒鸡简单,不用改动程序内核文件,不用懂php代码支持“加载更多”支持“无限下拉”支持动静态支持图片延迟加载插件的集成很简单,分以下几个步骤..

随便推点

Matlab读取二进制数据文件_matlab读取二进制文件-程序员宅基地

文章浏览阅读1.3w次,点赞4次,收藏67次。第一步:函数fopen打开文件fid=fopen('文件名',读取方式)fid:句柄值小于0表示打开失败;大于0表示打开成功文件名:字符串,使用单引号(本文例子'savedata.dat')读写方式:‘r’:只读方式打开文件(默认的方式),该文件已存在。‘r+’:读写方式打开文件,打开后先读后写。该文件已存在。‘w’:打开后写入数据。该文件已存在则更新;不存在则创建。‘w+’:读写方式打开文件。先读后写。该文件已存在则更新;不存在则创建。‘a’:在打开的文件末端添加数据。文件不存在则创_matlab读取二进制文件

Java虚拟机内存区域详解_java 获取虚拟机内存-程序员宅基地

文章浏览阅读211次。JVM 运行时的数据区域首先获取一个直观的认识:总共也就这么 5 个区(直接内存不属于 JVM 运行时数据区的一部分),除了程序计数器其他的地方都有可能出现 OOM (OutOfMemoryError),其中像是程序计数器和两个栈(Java 虚拟机栈 & 本地方法栈)都是每个线程要有一个的,所以肯定是线程隔离的。而其他 2 个区就是线程共享的了,也就是说,如果有多个..._java 获取虚拟机内存

excal造数据_char(97+rand()*26)-程序员宅基地

文章浏览阅读130次。然后右边滑块到上面 shfit+鼠标左键 框选数字填充创建随机英文名 选中单元格 =char(97+rand()*26)&char(97+rand()*26)&char(97+rand()*26)&char(97+rand()*26)&char(97+rand()*26)&char(97+rand()*26)随机生成时间选择日期 – 然后日期类型 -确定在此单元格输入—>之后自动生成(单元格右下角-黑色十-双击左键)自己理解._char(97+rand()*26)

浅谈kubernetes部署:UI部署_kubernetesui-程序员宅基地

文章浏览阅读1.6k次。在此之前请确认您已经按《配置docker私服密钥》的说明配置了私服密钥。根据以上内容可以了解到UI部署流程想了解更多详情,可以持续关注。修改相应image值为您的镜像目录。《openresty镜像制作》以阿里云docker私服举例。待网关部署完成后一起验证。_kubernetesui

[翻译] DSL和模型驱动开发的最佳实践(2/4)-程序员宅基地

文章浏览阅读73次。视点ViewPoints 一个软件系统通常情况下只用一个符号是不可能描述他所有的方面的, 此外,为了开发流程的需要,不同的方面,在不同的时间里,会被不同的角色描述,因为你要保证有一个干净的概念分离.因此,最重要的是找出描述一个系统不同概念的这些视点,为他们单独提供表现符号和抽象. 在一些系统中意味着你要为不同的关注点定义单独的..._dsl实践

扩散模型(Diffusion Model)最新综述!-程序员宅基地

文章浏览阅读1.7w次,点赞22次,收藏183次。点击上方“视学算法”,选择加"星标"或“置顶”重磅干货,第一时间送达本综述来自西湖大学李子青实验室、香港中文大学Pheng-Ann Heng和浙江大学陈广勇团队,对现有的扩散生成模型进行了全面的回顾。本文首先提出了diffusion model改进算法的细化分类与深度解析,同时对diffusion model的应用进行了系统的回顾,最后率先汇总领域内benchmarks。这也促进了后续工作《Dif...

推荐文章

热门文章

相关标签