package com.bwie.sixgroup.humbert;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import bean.User;
/**
* Created by acer on 2016/7/13.
*/
public class TiActivity extends Activity{
private TextView ti;
private AlertDialog alertDialog;
private ListView listview;
private String trim;
private String trim1;
private MyAdapter myAdapter;
private ImageView f;
private List<User> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ti);
listview = (ListView)findViewById(R.id.listview);
list = new ArrayList<User>();
f = (ImageView)findViewById(R.id.f);
f.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
ti = (TextView)findViewById(R.id.ti);
ti.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog();
}
});
}
public void showDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(TiActivity.this);
View view = View.inflate(TiActivity.this, R.layout.dialog,null);
final EditText dialog_wen = (EditText)view.findViewById(R.id.dialog_wen);
final EditText dialog_bu = (EditText)view.findViewById(R.id.dialog_bu);
Button btn_confrim = (Button)view.findViewById(R.id.btn_confrim);
Button btn_Cancel = (Button)view.findViewById(R.id.btn_Cancel);
btn_Cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
btn_confrim.setOnClickListener(new View.OnClickListener() {
private User user;
@Override
public void onClick(View v) {
trim1 = dialog_wen.getText().toString().trim();
trim = dialog_bu.getText().toString().trim();
if(!TextUtils.isEmpty(trim) && !TextUtils.isEmpty(trim1)){
list.add(new User(trim,trim1));
alertDialog.dismiss();
Toast.makeText(TiActivity.this,"您还没有提问",Toast.LENGTH_SHORT).show();
}
qwe();
alertDialog.dismiss();
}
});
builder.setView(view);
alertDialog = builder.create();
alertDialog.show();
}
public void qwe(){
if(myAdapter == null){
myAdapter = new MyAdapter();
listview.setAdapter(myAdapter);
}else{
myAdapter.notifyDataSetChanged();
}
}
class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = View.inflate(TiActivity.this, R.layout.tilistitem,null);
TextView ti_ti = (TextView)convertView.findViewById(R.id.ti_ti);
TextView ti_tv = (TextView) convertView.findViewById(R.id.ti_tv);
ti_ti.setText(list.get(position).getNames());
ti_tv.setText(list.get(position).getName());
return convertView;
}
}
}