这里写目录标题
星级评分条RattingStar
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="评分" />
<RatingBar
android:id="@+id/ratingBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="提交" />
</LinearLayout>
//评分部分
Button submit = findViewById(R.id.button);
RatingBar ratingBar = findViewById(R.id.ratingBar2);
EditText editText = findViewById(R.id.editTextTextPersonName);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str = "";
str+=editText.getText().toString();
Toast.makeText(MainActivity.this, "评价内容:"+str+"\n评分:"+ratingBar.getRating(), Toast.LENGTH_LONG).show();
}
});
效果图:
自动完成文本框
<AutoCompleteTextView
android:layout_marginTop="200px"
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
//自动完成文本框部分
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
String[] strings = new String[]{"android","android studio","android sdk"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,R.layout.text,strings);
autoCompleteTextView.setAdapter(adapter);
其中R.layout.text实在layout目录下定义的一个layout recourse file,根标签为textView,用于显示文本提示框。
运行效果: