由于项目比较简单,直接贴代码块:
main_layout布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.xiaoke.commentdemo.MainActivity">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
<LinearLayout
android:id="@+id/ll_cmt"
android:visibility="gone"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_comment"
android:background="#e1e1e1"
android:hint="请输入想说的话"
android:textSize="14sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
mainactivity
package com.example.xiaoke.commentdemo;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
public class MainActivity extends Activity {
private ListView lv;
private ComtAdapter adapter;
private LinearLayout ll_cmt;
private EditText et_comment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv= (ListView) findViewById(R.id.lv);
ll_cmt= (LinearLayout) findViewById(R.id.ll_cmt);
et_comment= (EditText) findViewById(R.id.et_comment);
adapter=new ComtAdapter(getApplicationContext());
lv.setAdapter(adapter);
adapter.setOncomtOnclickListener(new ComtAdapter.OncomtOnclickListener() {
@Override
public void onComtClickListener() {
et_comment.setHint("说点什么吧...");
ll_cmt.setVisibility(View.VISIBLE);
et_comment.requestFocus();//获取焦点,并弹出软键盘
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
});
}
}
评论适配器
package com.example.xiaoke.commentdemo;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* 列表适配器
* Q164454216
* Created by xiaoke on 2017/1/2.
*/
public class ComtAdapter extends BaseAdapter {
private Context context;
public ComtAdapter(Context context){
this.context=context;
}
/**
* 点击评论回掉接口
*/
public interface OncomtOnclickListener{
void onComtClickListener();//自行添加需要传的参数
}
private OncomtOnclickListener oncomtOnclickListener;
public void setOncomtOnclickListener(OncomtOnclickListener oncomtOnclickListener){
this.oncomtOnclickListener=oncomtOnclickListener;
}
@Override
public int getCount() {
return 4;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view=View.inflate(context,R.layout.item_comt_layout,null);
TextView tv_cmt= (TextView) view.findViewById(R.id.tv_cmt);
tv_cmt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
oncomtOnclickListener.onComtClickListener();
}
});
return view;
}
}
列表子布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="80dp">
<TextView
android:gravity="center"
android:text="我是评论的子条目"
android:layout_width="match_parent"
android:layout_height="80dp" />
<TextView
android:id="@+id/tv_cmt"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#999999"
android:gravity="center"
android:text="评论"
android:textColor="#333333"
android:layout_width="60dp"
android:layout_height="20dp" />
</RelativeLayout>
项目比较简单,主要运用接口回调给主界面弹出editext可以编辑评论,供初学者参考。
项目地址:http://download.csdn.net/detail/wxk105/9726978