好评系统
package com.example.app3;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Context context;
private Button anniu;
private ImageView esc;
private Button talk;
private Button fiveok;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
anniu = (Button) findViewById(R.id.anniu);
anniu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.mipmap.ic_launcher);
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.custom, null);
esc = (ImageView) view.findViewById(R.id.esc);
talk = (Button) view.findViewById(R.id.talk);
fiveok = (Button) view.findViewById(R.id.fiveok);
talk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "吐槽啥呢,不许吐槽", Toast.LENGTH_SHORT).show();
}
});
fiveok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "谁允许你五星好评了?????", Toast.LENGTH_SHORT).show();
}
});
builder.setView(view);
final AlertDialog alertDialog = builder.create();
esc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
alertDialog.show();
}
});
}
}
布局代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:gravity="center"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:background="#13B6FF"
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="@+id/esc"
android:layout_alignParentRight="true"
android:src="@mipmap/ic_launcher_round"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="120dp"
android:layout_marginLeft="170dp"
android:text="评价一下吧"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:text="喜欢吗?给个五星好评给老子,鼓励一下老子"
android:gravity="center"
android:layout_width="200dp"
android:layout_height="50dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<Button
android:id="@+id/talk"
android:text="老子要吐槽"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/fiveok"
android:text="五星好评"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
package com.example.app4;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private ListView list;
private List<User> lists=new ArrayList<>();
private List<HashMap<String,Object>> liste=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.list);
String[] name = getResources().getStringArray(R.array.name);
String[] number = getResources().getStringArray(R.array.number);
Log.i("TAG", "onCreate: "+name);
for (int i = 0; i < name.length; i++) {
HashMap<String, Object> map = new HashMap<>();
map.put("name",name[i]);
map.put("number",number[i]);
Log.i("TAG", "onCreate: "+map);
liste.add(map);
}
MyAdapter myAdapter = new MyAdapter(this, lists,liste);
list.setAdapter(myAdapter);
}
}