Movie Rating Apps
Movie Rating Apps
Movie Rating Apps
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/Movie_name"
android:id="@+id/editText2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/linearLayout1">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/editText3"
android:layout_weight="1"
android:inputType="number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:hint="@string/Duration"
android:layout_weight="1"
android:id="@+id/editText4" />
</LinearLayout>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar1"
android:clickable="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/editText1"
android:text=""
android:hint="@string/Write_Review"
android:layout_weight="1"
android:gravity="top"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText5"
android:text=""
android:hint="@string/Starring"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText6"
android:text=""
android:hint="@string/Director"
android:clickable="true"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Save"
android:id="@+id/button1"/>
</LinearLayout>
Menjadi
if(str1.equalsIgnoreCase("") || str2.equalsIgnoreCase("")
|| str3.equalsIgnoreCase("") || str5.equalsIgnoreCase("")
|| str4.equalsIgnoreCase("") || str.equalsIgnoreCase(""))
{
Toast.makeText(MainActivity.this,"Please fill all the fields.", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this,"Validation successful", Toast.LENGTH_SHORT).show();
}
}
}
1. Tambahkan sebuah spinner pada layout activity_main.xml, dan letakkan di bawah editText2
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner1"/>
movieDirector.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent mAutoCompleteIntent = new
Intent(MainActivity.this, DirectorName.class); //DirectorName.java harus dibuat sebuah CLass Baru
startActivityForResult(mAutoCompleteIntent, 0123456);
}
});
if(mGenres.getSelectedItem().toString().equalsIgnoreCase("-Select Genre-")){
Toast.makeText(MainActivity.this,"Please Select valid Genre",
Toast.LENGTH_SHORT).show();
return;
}
8. Tambahkan code berikut setelah bagian public class OnButtonClick implements OnClickListener
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try{
if ((requestCode == 0123456 ) && (resultCode ==
Activity.RESULT_OK)){
Bundle myResults = data.getExtras();
String vresult = myResults.getString("key");
movieDirector.setText(vresult);
}
}
catch (Exception e) {
movieDirector.setText("Oops! - " + requestCode + " " +
resultCode);
}
}
<TextView android:text="@string/dname"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<AutoCompleteTextView
android:layout_width="match_parent"
android:text=""
android:layout_height="wrap_content"
android:id="@+id/autoCompleteTextView1">
<requestFocus></requestFocus>
</AutoCompleteTextView>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Finish"
android:id="@+id/button1"/>
</LinearLayout>
15. Setelah public class DirectorName extends AppCompatActivity { Tambahkan code berikut :
private AutoCompleteTextView mDirectorName;
private Button mFinishButton;
mDirectorName.setAdapter(adapter);
mFinishButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mBundle.putString("key",
mDirectorName.getText().toString());
mIntent.putExtras(mBundle);
setResult(Activity.RESULT_OK, mIntent);
finish();
}
});