public class MainActivity extends Activity {
public static MediaPlayer mediaPlayer;
public static MediaPlayer smediaPlayer;
private int musi1, musi2, boo;
private EditText search;
private MyListAdapter listAdapter;
private ExpandableListView myList;
private ArrayList<Continent> continentList = new ArrayList<Continent>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
boo = 0;
myList = (ExpandableListView) findViewById(R.id.expandableListView1);
search = (EditText) findViewById(R.id.SearchText);
displayList();
search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
boo = 1;
String text = search.getText().toString().toLowerCase(Locale.getDefault());
listAdapter.filterData(text);
}
});
myList.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
long id) {
if (boo == 0) {
if (groupPosition == 0) {
musi1 = 0;
} else if (groupPosition == 1) {
musi1 = 1;
} else if (groupPosition == 2) {
musi1 = 2;
} else if (groupPosition == 3) {
musi1 = 3;
} else if (groupPosition == 4) {
musi1 = 4;
} else if (groupPosition == 5) {
musi1 = 5;
} else if (groupPosition == 6) {
musi1 = 6;
} else {
}
if (childPosition == 0) {
musi2 = 0;
} else if (childPosition == 1) {
musi2 = 1;
} else if (childPosition == 2) {
musi2 = 2;
} else if (childPosition == 3) {
musi2 = 3;
} else if (childPosition == 4) {
musi2 = 4;
} else if (childPosition == 5) {
musi2 = 5;
} else if (childPosition == 6) {
musi2 = 6;
} else {
}
} else {
}
intend();
return false;
}
});
}
private void intend() {
if (musi1 == 0 && musi2 == 0) {
Intent intent = new Intent(MainActivity.this, aitai_gumi.class);
startActivity(intent);
} else if (musi1 == 0 && musi2 == 1) {
Intent intent = new Intent(MainActivity.this, aitai_hanatan.class);
startActivity(intent);
} else if (musi1 == 0 && musi2 == 2) {
Intent intent = new Intent(MainActivity.this, aitai_hxp.class);
startActivity(intent);
} else if (musi1 == 0 && musi2 == 3) {
Intent intent = new Intent(MainActivity.this, aitai_kano.class);
startActivity(intent);
} else if (musi1 == 1 && musi2 == 0) {
Intent intent = new Intent(MainActivity.this, alice_miku.class);
startActivity(intent);
}
}
package android.example.view;
import java.util.ArrayList;
import com.example.utaite.R;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<Continent> continentList;
private ArrayList<Continent> originalList;
public MyListAdapter(Context context, ArrayList<Continent> continentList) {
this.context = context;
this.continentList = new ArrayList<Continent>();
this.continentList.addAll(continentList);
this.originalList = new ArrayList<Continent>();
this.originalList.addAll(continentList);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<Country> countryList = continentList.get(groupPosition).getCountryList();
return countryList.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
Country country = (Country) getChild(groupPosition, childPosition);
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.child_row, null);
}
TextView code = (TextView) view.findViewById(R.id.cv_group1);
TextView name = (TextView) view.findViewById(R.id.cv_group2);
code.setText(country.getCode().trim());
name.setText(country.getName().trim());
return view;
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<Country> countryList = continentList.get(groupPosition).getCountryList();
return countryList.size();
}
@Override
public Object getGroup(int groupPosition) {
return continentList.get(groupPosition);
}
@Override
public int getGroupCount() {
return continentList.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) {
Continent continent = (Continent) getGroup(groupPosition);
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.group_row, null);
}
ImageView heading0 = (ImageView) view.findViewById(R.id.iv_image);
heading0.setImageResource(continent.getIcon());
TextView heading1 = (TextView) view.findViewById(R.id.tv_group1);
heading1.setText(continent.getName1().trim());
TextView heading2 = (TextView) view.findViewById(R.id.tv_group2);
heading2.setText(continent.getName2().trim());
return view;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void filterData(String query) {
query = query.toLowerCase();
Log.v("MyListAdapter", String.valueOf(continentList.size()));
continentList.clear();
if (query.isEmpty()) {
continentList.addAll(originalList);
} else {
for (Continent continent : originalList) {
ArrayList<Country> countryList = continent.getCountryList();
ArrayList<Country> newList = new ArrayList<Country>();
for (Country country : countryList) {
if (country.getCode().toLowerCase().contains(query)
|| country.getName().toLowerCase().contains(query)) {
newList.add(country);
}
}
if (newList.size() > 0) {
Continent nContinent = new Continent(continent.getIcon(), continent.getName1(),
continent.getName2(), newList);
continentList.add(nContinent);
}
}
}
Log.v("MyListAdapter", String.valueOf(continentList.size()));
notifyDataSetChanged();
}
}
안녕하세요. 안드로이드 공부하는 학생입니다.
현재 리스트뷰는 Expandablelist View 쓰고 있구요
Child 검색은 되는데 위에 보시다시피 인텐트를 포지션으로 설정해둬서 사실상 쓸모가 없습니다 ..
검색해서 최상위권으로 올라오면 groupPosition childPosition 전부 0 0 으로 들어가서 다른 클래스로 인텐트 되더라고요 ㅠㅠㅠ
구글링한 코드가 많아서 뒤죽박죽이기에 너무 부끄러운 코드지만 .. 해결방법좀 자세히 알려주시면 감사하겠습니다