PLEASE help with ListView I cant solve this alone :(

PopCole

New member
Sep 5, 2015
1
0
0
Visit site
Hi. I'm new in Android development (I'm not that bad in networking, web development, c sharp.. but here Im big noob). As my first task (after spending some time with books) I decided to make Class Schedule fore my daughter. So, I end up with huge problems with ListView (simple_expandable_list_item_1). Finally, I found some code online and (in the last few days) I'm trying to make it work. Probably I messed up a lot, but I really hope that someone can help.

ListViewID is raspView

I put code in Notepad file because I can't post it in here :(
 

Attachments

  • JavaCodeForClassSch.txt
    3.6 KB · Views: 8

Golfdriver97

Trusted Member Team Leader
Moderator
Dec 4, 2012
35,367
113
63
Visit site
Welcome to the forums. Programming and development is somewhat outside the scope of this forum. There may be some people here who can help, but the question will be if they see it.

I will post the code for you and then delete the attachment.
 

Golfdriver97

Trusted Member Team Leader
Moderator
Dec 4, 2012
35,367
113
63
Visit site
Here is the lines of code:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SimpleExpandableListAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.SimpleCursorTreeAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


//Prvi Deo
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>() {{
add(new HashMap<String, String>() {{
put("ROOT_NAME", "Group 1");
}});
add(new HashMap<String, String>() {{
put("ROOT_NAME", "Group 2");
}});
}};

List<List<Map<String, String>>> listOfChildGroups = new ArrayList<List<Map<String, String>>>();

List<Map<String, String>> childGroupForFirstGroupRow = new ArrayList<Map<String, String>>(){{
add(new HashMap<String, String>() {{
put("CHILD_NAME", "child in group 1");
}});
add(new HashMap<String, String>() {{
put("CHILD_NAME", "child in group 1");
}});
}};
listOfChildGroups.add(childGroupForFirstGroupRow);

List<Map<String, String>> childGroupForSecondGroupRow = new ArrayList<Map<String, String>>(){{
add(new HashMap<String, String>() {{
put("CHILD_NAME", "child in group 2");
}});
add(new HashMap<String, String>() {{
put("CHILD_NAME", "child in group 2");
}});
}};
listOfChildGroups.add(childGroupForSecondGroupRow);


//Drugi Deo
new SimpleExpandableListAdapter(
this,
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { "ROOT_NAME" },
new int[] { android.R.id.text1 },

listOfChildGroups,
android.R.layout.simple_expandable_list_item_2,
new String[] { "CHILD_NAME", "CHILD_NAME" },
new int[] { android.R.id.text1, android.R.id.text2 }

);

ListAdapter casAdapter = new ArrayAdapter<String>(this, android.R.layout.expandable_list_content);

ListView raspView = (ListView) findViewById(R.id.raspView);
raspView.setAdapter(casAdapter);
}

@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_main, 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);
}
}
 

Trending Posts

Forum statistics

Threads
943,152
Messages
6,917,537
Members
3,158,848
Latest member
kerokekerol