I am working on a menu list for an app I am making. I followed this tutorial for creating it (changing values as needed) - http://www.ezzylearning.com/tutorial.aspx?tid=1763429.
Now my list isn't super complex. It's going to have the same data every time and there is only two sections. So far, I have my list working but I need to replace the 7th item with a different view/layout in xml or to add that view in.
Current Code....
Main Activity:
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
public class HU_main extends Activity {
private ListView f_menu;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hu_main);
Front_menu front_menu_data[] = new Front_menu[] {
new Front_menu("Cadences", "Reference chart of all the primary cadences."),
new Front_menu("Chords and Non-Chord Tones", "Reference chart of chord types and non-chord tones and associated rules of NCTs."),
new Front_menu("Key Signatures", "Reference chart for key signature rules."),
new Front_menu("Scale/Mode Triads", "List of triads and degrees for all standard diatonic scale modes."),
new Front_menu("Harmonic Progression", "Reference chart for scale and mode chord progressions."),
new Front_menu("Terminology Translation", "Reference list if primary music terms and instruments in German, Italian and French."),
new Front_menu("Replace", "Replace"),
new Front_menu("Chord Finder", "Enter notes to find chords."),
new Front_menu("Modulation", "Reference chart of chord types and non-chord tones and associated rules of NCTs."),
new Front_menu("Scale Finder", "Find scales and modes by notes."),
new Front_menu("Transposition", "Show changes to and from concert pitch for transposing instruments or determine overall transposition of key.")
};
Front_menuAdapter adapter = new Front_menuAdapter(this,
R.layout.item_layout, front_menu_data);
f_menu = (ListView)findViewById(R.id.f_menu);
f_menu.setAdapter(adapter);
}
}
Front_menuAdapter:
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class Front_menuAdapter extends ArrayAdapter{
Context context;
int layoutResourceId;
Front_menu data[] = null;
public Front_menuAdapter(Context context, int layoutResourceId, Front_menu[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
Front_menuHolder holder = null;
if(row == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new Front_menuHolder();
holder.txtTitle1 = (TextView)row.findViewById(R.id.menu_item);
holder.txtTitle2 = (TextView)row.findViewById(R.id.item_description);
row.setTag(holder);
}
else {
holder = (Front_menuHolder)row.getTag();
}
Front_menu front_menu = data[position];
holder.txtTitle1.setText(front_menu.item);
holder.txtTitle2.setText(front_menu.desc);
return row;
}
class Front_menuHolder {
TextView txtTitle1;
TextView txtTitle2;
}
}
Front_menu (constructor):
public class Front_menu {
public String item;
public String desc;
public Front_menu() {
super();
}
public Front_menu(String item, String desc) {
super();
this.item = item;
this.desc = desc;
}
}
.
stackoverflow.comm
No comments:
Post a Comment