Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Abdulmajeed Alroumi
3,719 PointsVoting system in self destructing message app
Hello guys,
I have been going through build self destructing message app. It has been successful so far. At the moment I am trying to include voting system in the app as the user will write his/her own questionnaire, send it over to a friend. The friend opens it from his/her inbox, answer the questionnaire by clicking the RadioButton and click a button to send it back to the user.
Here is what I have done so far:
I created a class called VoteActivity:
public class VoteActivity extends ActionBarActivity {
protected EditText mainText;
protected EditText mTextOne;
protected EditText mTextTwo;
protected EditText mTextThree;
protected Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vote);
mainText = (EditText) findViewById(R.id.questionVote);
mTextOne = (EditText) findViewById(R.id.choiceOne);
mTextTwo = (EditText) findViewById(R.id.choiceTwo);
mTextThree = (EditText) findViewById(R.id.choiceThree);
mButton =(Button) findViewById(R.id.createQ);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Quiestionare = mainText.getText().toString();
String choiceOne = mTextOne.getText().toString();
String choiceTwo = mTextTwo.getText().toString();
String choiceThree = mTextThree.getText().toString();
Quiestionare.trim();
choiceOne.trim();
choiceTwo.trim();
choiceThree.trim();
if (Quiestionare.isEmpty() || choiceOne.isEmpty() || choiceTwo.isEmpty()|| choiceThree.isEmpty())
{
AlertDialog.Builder builder = new AlertDialog.Builder(VoteActivity.this);
builder.setMessage(R.string.voteMessage)
.setTitle(R.string.vote_error_title)
.setPositiveButton(android.R.string.ok,null);
AlertDialog dialog = builder.create();
dialog.show();
}
else
{
ParseObject post = new ParseObject("Post");
post.put("questionare", mainText);
post.put("optionOne", mTextOne);
post.put("optionTwo", mTextTwo);
post.put("optionThree", mTextThree);
post.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e==null) {
// questioner posted successfully
Toast.makeText(getApplicationContext(), "Sent", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(VoteActivity.this, recipientsActivity.class);
startActivity(intent);
}
else {
Toast.makeText(getApplicationContext(), "Failed to post", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_vote, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Now, next I am planing to go inboxFragment and added a column in my parse table so when the user vote it is saved in the background.
I would love it anyone could show more direction in this matter
Thank you very much in advance