Activity_main.
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnCreateSurvey"
android:text="Create Survey"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btnTakeSurvey"
android:text="Take Survey"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btnViewSummary"
android:text="View Summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Main_activity.java
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
Button btnCreateSurvey, btnTakeSurvey, btnViewSummary;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btnCreateSurvey = findViewById([Link]);
btnTakeSurvey = findViewById([Link]);
btnViewSummary = findViewById([Link]);
[Link](v ->
startActivity(new Intent([Link],
[Link])));
[Link](v ->
startActivity(new Intent([Link],
[Link])));
[Link](v ->
startActivity(new Intent([Link],
[Link])));
}
}
activity_create_survey.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editTextOption"
android:hint="Enter Question"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/buttonAddOption"
android:text="Add option"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup
android:id="@+id/radioGroupOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
public class CreateSurveyActivity extends AppCompatActivity {
EditText editTextOption;
Button buttonAddOption;
DBHelper dbHelper;
RadioGroup radioGroupOptions;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_create_survey);
editTextOption = findViewById([Link]);
buttonAddOption = findViewById([Link]);
radioGroupOptions = findViewById([Link]);
dbHelper = new DBHelper(this);
[Link](v -> {
String question = [Link]().toString();
if ([Link]()) {
[Link](this, "Enter a question",
Toast.LENGTH_SHORT).show();
return;
}
SQLiteDatabase db = [Link]();
ContentValues values = new ContentValues();
[Link]("question", question);
[Link]("options", null, values);
[Link](this, "Question Added", Toast.LENGTH_SHORT).show();
[Link]("");
});
}
activity_take_survey.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewQuestion"
android:text="Question"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rbOption1"
android:text="Neutral"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rbOption2"
android:text="Good"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/rbOption3"
android:text="Excellent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
<Button
android:id="@+id/buttonSubmit"
android:text="Submit Answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
public class TakeSurveyActivity extends AppCompatActivity {
TextView textViewQuestion;
RadioGroup radioGroup;
Button buttonSubmit;
DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_take_survey);
textViewQuestion = findViewById([Link]);
radioGroup = findViewById([Link]);
buttonSubmit = findViewById([Link]);
dbHelper = new DBHelper(this);
// Load question from database
loadQuestion();
// Submit button logic
[Link](v -> {
int selectedId = [Link]();
if (selectedId == -1) {
[Link](this, "Please select an option",
Toast.LENGTH_SHORT).show();
return;
}
RadioButton selectedRadioButton = findViewById(selectedId);
String answer = [Link]().toString();
SQLiteDatabase db = [Link]();
ContentValues values = new ContentValues();
[Link]("answer", answer);
[Link](DBHelper.TABLE_RESPONSES, null, values);
[Link](this, "Answer Saved", Toast.LENGTH_SHORT).show();
[Link](); // reset selection
});
}
// ✅ CORRECT: Separate method (outside onCreate)
private void loadQuestion() {
SQLiteDatabase db = [Link]();
Cursor cursor = [Link](
"SELECT * FROM " + DBHelper.TABLE_QUESTIONS + " LIMIT 1",
null);
if ([Link]()) {
String question = [Link](1);
[Link](question);
}
[Link]();
}
}
activity_summary.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textViewSummary"
android:padding="20dp"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class SummaryActivity extends AppCompatActivity {
TextView textViewSummary;
DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_summary);
textViewSummary = findViewById([Link]);
dbHelper = new DBHelper(this);
displaySummary();
}
private void displaySummary() {
SQLiteDatabase db = [Link]();
Cursor cursor = [Link](
"SELECT answer, COUNT(*) FROM " +
DBHelper.TABLE_RESPONSES +
" GROUP BY answer", null);
StringBuilder result = new StringBuilder();
while ([Link]()) {
[Link]([Link](0))
.append(" : ")
.append([Link](1))
.append("\n");
}
[Link]([Link]());
[Link]();
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "SurveyDB";
public static final int DATABASE_VERSION = 1;
public static final String TABLE_QUESTIONS = "questions";
public static final String TABLE_RESPONSES = "responses";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
[Link]("CREATE TABLE " + TABLE_QUESTIONS +
"(id INTEGER PRIMARY KEY AUTOINCREMENT, question TEXT)");
[Link]("CREATE TABLE " + TABLE_RESPONSES +
"(id INTEGER PRIMARY KEY AUTOINCREMENT, answer TEXT)");
[Link]("CREATE TABLE options(id INTEGER PRIMARY KEY AUTOINCREMENT,
option_text TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
[Link]("DROP TABLE IF EXISTS " + TABLE_QUESTIONS);
[Link]("DROP TABLE IF EXISTS " + TABLE_RESPONSES);
onCreate(db);
}
}