• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Replace Single Row View in a Custom STATIC ListView, STATIC Data

Right so I have Eclipse Juno and I'm working on an app with that.

The main activity will have a scrollable menu that takes you to all the other activities.

So the general structure/outline right now:
[HIGH]Relative Layout
ImageView (header logo type thing)
ListView (the actual scrollable menu)[/HIGH]​
Here's the problem though... I can't find any simple list tutorials. I can easily make a single line list work but I need to make a two line list and one that is static, not dynamic and no examples are out there for that. It's like if you want to make a 2 line list, you can only learn how to do it in the most code-heavy ridiculous way possible.

Essentially what I am looking for with the list is this:
 
Seriously, is there not ONE example out there of a static list with static data that has more than one line per item?

Come on... really? I have been Googling for a week now and the option is either: static but you only get one line or dynamic but you need way more code than just what you want.

I can't find a single one, not ONE with static custom view, static data, simple adapter to bind the data to the proper parts.

It goes from simple static to ******ed complex dynamic and nothing in between and I've been on 3 or 4 different forums and not one response on any of them...
 
android:title="title of thing" android:summary="description of thing"
For a regular list view?

How do you implement that? Obviously that's XML but where? In the custom layout? I still can't get the data from the string-array in resources to the actual list regardless of naming convention...
 
String myData[] = getResources().getStringArray(R.array.xxxxxxxx);

That will take the strings you have in your array from resources and put them into a String array in the class. Change the xxxxxxxx to whatever you named the array.


I still can't get the data from the string-array in resources to the actual list regardless of naming convention...
 
* EDITED: Monday, 1 April 2013 06:43 GMT

Let me update this what I have. I followed this tutorial for what I created below and tried to modify it: Customizing Android ListView Items with Custom ArrayAdapter Tutorial in Category Android at EzzyLearning.com

Now, the relevant code stuff:

The front Menu XML code (a sub item of the main activity):
[HIGH]<ListView
android:id="@+id/f_menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/imageView1"
android:layout_marginTop="5dp"
android:divider="@drawable/divider"
android:dividerHeight="1dp"
android:headerDividersEnabled="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideOverlay"
android:visibility="visible"
tools:context=".HU_main"
tools:listheader="@layout/menu_header"
tools:listitem="@layout/item_layout" >

</ListView>[/HIGH]

The Java class for the main activity:
[HIGH]import android.app.Activity;
import android.os.Bundle;
import android.view.View;
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(getResources().getStringArray(R.array.resources_item),
getResources().getStringArray(R.array.resources_description))
};

Front_menuAdapter adapter = new Front_menuAdapter(this,
R.layout.item_layout, front_menu_data);



f_menu = (ListView)findViewById(R.id.f_menu);

View header = (View)getLayoutInflater().inflate(R.layout.menu_header, null);
f_menu.addHeaderView(header);

f_menu.setAdapter(adapter);

}


}

[/HIGH]

The custom adapter:
[HIGH]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<Front_menu>{
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;
}

}[/HIGH]

The custom constructor used in the custom adapter:
[HIGH]package com.impetusaesthetica.harmoniauniversali;

public class Front_menu {
public String item;
public String desc;
public Front_menu(String[] item, String[] desc) {
super();
}

public Front_menu(String item, String desc) {
super();
this.item = item;
this.desc = desc;
}

}[/HIGH]

Now the string arrays are in resources.
String-arrays:
 
I back tracked a bit from the previous message and to make a long story short because I haven't the time...

This is what throws an error and I know why:
[HIGH]Front_menu front_menu_data[] = new Front_menu[] {
new Front_menu(getResources().getStringArray(R.array.resources_item),
getResources().getStringArray(R.array.resources_description))
};[/HIGH]

All the way back in the other class, it expects an array of strings, not an array of a string-array.

SO

I need to take getResources().getStringArray(R.array.resources_item) and wrap all of that in something which can convert that into all strings in the array...

I'm almost ready to copy/paste over that crap and just be done with it and manually enter it in.
 
OK so I decided it would be much less of a hassle to just take the data out of resources and put it in the Java adapter code and it works.

Fantastic.

Now I have another list and I need to merge it into this one. So far, in all my searching, I can find no code to do this with.

Essentially what I have now is working with that list and I need to add another list to it or add another section. The list will only be two total sections and all the code can find in searching is for non-static lists or for lists with variable data and so on and/or is highly inefficient and doesn't give you the custom header the way I have my header (it gives a simple bar divider).

Without going through everything again, this is the java behind the main activity:
[HIGH]package com.impetusaesthetica.harmoniauniversali;


import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;


public class HU_main extends Activity {

private ListView f_menu;
private ListView f_menu2;

@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("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.")
};

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);





//*the other set of data, which is temporarily*//
//*place into another listview on the same activity*//

Front_menu front_menu_data2[] = new Front_menu[] {
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.")
};


Front_menuAdapter adapter2 = new Front_menuAdapter(this,
R.layout.item_layout, front_menu_data2);

f_menu2 = (ListView)findViewById(R.id.f_menu2);

f_menu2.setAdapter(adapter2);



}

}
[/HIGH]
 
I suppose what I can do is put all the data for both lists (since they follow the same format) into the one and use some type of code to insert the second header in where it is supposed to be.

What would that code be though?
 
So... here's what I have now:
[HIGH]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);

}


}[/HIGH]
What I want to do now is I need to replace a single row view. Specifically the one that is or should be 7 in the index (static and if I add more to the first half of the list, I can just change the index number): "new Front_menu("Replace", "Replace")"

I want to replace the entire row with a specific layout that doesn't need it's data bound to it (it's a section header).

I tried finding the necessary code, but all the code is for dynamic lists. Why people have so much against static is against me but, whatever.

Anyway, I don't need to dynamically do anything. I just need to override that single row and replace it with a new view.

I can't seem to get anything to work though from what I find (because their code is all for one dynamic list rather than a single list through an array and constructor that are in separate Java files from the java backing behind the actual activity)...
 
Back
Top Bottom