Can someone explain this Picasso Adapter for GridView? - android

I'm kinda new in android development also in Stackoverflow (sorry because this question is kinda not following the rules) so, i want to ask something about this tutorial
EDIT : i just figure it myself and i got an error in "listview.setAdapter"
public class UsageExampleAdapter extends AppCompatActivity {
public static String[] eatFoodyImages = {
"http://i.imgur.com/rFLNqWI.jpg",
"http://i.imgur.com/C9pBVt7.jpg",
"http://i.imgur.com/rT5vXE1.jpg",
"http://i.imgur.com/aIy5R2k.jpg",
"http://i.imgur.com/MoJs9pT.jpg",
"http://i.imgur.com/S963yEM.jpg",
"http://i.imgur.com/rLR2cyc.jpg",
"http://i.imgur.com/SEPdUIx.jpg",
"http://i.imgur.com/aC9OjaM.jpg",
"http://i.imgur.com/76Jfv9b.jpg",
"http://i.imgur.com/fUX7EIB.jpg",
"http://i.imgur.com/syELajx.jpg",
"http://i.imgur.com/COzBnru.jpg",
"http://i.imgur.com/Z3QjilA.jpg",
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usage_example_adapter);
listView.setAdapter(new ImageListAdapter(UsageExampleAdapter.this, eatFoodyImages));
}
}

When you make an android application basic folders are created by IDE.As per android directory structure xml file which represent layout of application should be located in res->layout folder. As per my suggestion it is better to get overview of android from rather than jump into project.http://developer.android.com/tools/projects/index.html

Related

Creating Object from other class

I have a settings screen where you can choose between, add and remove configurations for the app.
When adding a configuration, I create a new Instance of a inputBox Class (extending the settings activity class - where I stored the procedure for the standard android text input box) to query the name for the new configuration.
In the Onclick of this inputbox a procedure from the superClass (the settings-activity) is called to create a new configuration object.
This Procedure queries some things from the activity (e.g. selected spinner element) including the progress of a seekBar.
This is where I get a NPE:
java.lang.NullPointerException: Attempt to invoke virtual method'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
The same object creation procedure is also called on initialization of the app and works just fine.
I understand from the Error that the issue is that when calling the procedure from a child class the reference of the variables to the corrseponding elements of the screen is not set anymore - and therefore cannot be queried.
So the question:
How can I query values of activity elements, when the procedure is called from another class?
I know that the topic is quite broad, but I can't figure it out for a couple of days now
Thanks for your help in advance.
Here is a scheme of the problem:
public class Settings extends AppCompatActivity{
Context settingsContext = this;
private Spinner someSpinner;
//other elements
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
someSpinner = (Spinner) findViewById(R.id.someView);
//other elements
addNewConfig.setOnClickListener((v) --> {
inputBox inputBox = new inputBox("OK", "Cancel", settingsContext, "sourcePath",1,1);
newConfigName = inputBox.show();
});
public sSetting makeNewConfig(String name, String sourcePath, int dataFrom, int dataTo){
sSetting newConfig;
newConfig = new sSetting("NAME", someSpinner.getProgress()>0, ...);
return newConfig;
}
}
And the inputBox:
public final class inputBox extends Settings {
//someVars
inputBox(String buttonOk, String buttonCancel, Context setContext, String sourcePath, int dataFrom, int dataTo){
//variable setters
}
private String show() {
//show msgbox
//onclick ok
super.makeNewConfig(....);
}
For solving the problem I restructured my Project a little:
I removed the inputBox-Part, which, after some research considered for a too complicated solution for what I needed anyway.
However: I now added a editText to my Settings View.
Although I had to change my Settings view for this, it now looks better and it was ridiculously easy to edit the configuration name for the user.
I think in most cases that will do the trick. Adding Popup-Boxes just needs more error handling and makes the design more complicated
I hope this helps ;)
If you need the code for it it is available here:
GitHub - AIM

Const.EXTRA_DATA error

I am new in SO, and also new in Android. I try to make some chat application and I want to use this code
ListView list = (ListView) findViewById(R.id.listUser);
list.setAdapter(new UserAdapter());
list.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startActivity(new Intent(UserList.this, Chat.class).putExtra(Const.EXTRA_DATA, uList.get(pos).getUsername()));
}
});
But the problem, there is error for Const.EXTRA_DATA because it can not be resolved and also uList.get(pos) too, I use Android Studio. I got that code from video tutorial.
from the comments you understood that Const is a predefined class, unfortunately it is not, there is no such class available in android library.
so your code will be like
startActivity(new Intent(UserList.this, Chat.class).putExtra("EXTRA_DATA_KEY", uList.get(pos).getUsername()));
since the key has to be used in both activities (sending activities and receiving activity) usually defines in a separate Java file.
Hello dear you are using your code snippet like
Const.EXTRA_DATA
right?
--> as you told us you are new SO please check your are having
class named
Const and
having static string variable like
EXTRA_DATA
-> SO finaly your class will appear like
public class Const{
public static String EXTRA_DATA="EXTRA_DATA";
}

Getting "Source not found" when debugging my own files on android

This problems occurs when I'm debugging any android application on eclipse. Let´s say I've got 2 classes, each on a different file but on the same package:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
<BREAKPOINT> DummyClass.doSomething();
}
...
}
----------------
public class DummyClass {
public static diSomething(){
Log.e("TAG","HELLO");
}
}
When the execution stops at the breakpoint, I want to step into, to get to the DummyClass. However, I get a "Source not found" error, saying that android.jar is not accessible. Why? I'm not even trying to access that code.
I would appreciate much any help you you give me.
Looks like there is a spelling mistake in your code.
You have DummyClass.doSomething();and
public class DummyClass {
public static *diSomething*(){
Log.e("TAG","HELLO");
}
}
Change it to 'doSomething()' instead of diSomething()

android - How to backup the data without using database even if the app closes

In my application i want to maintain data without using the local DB even if the application closes. For this i created one class in my app, in that i created static variables so we can access them anywhere in the app. But here some times data is gone i don't know why it's happen. this process is good or any better is there? Somewhere i read that Shared Preferences is useful but i don't know about that.please can anyone share your ideas.
public class AJ_Constant {
//New Food Item
public static String strEntrySavedFoodItem = "";
public static String strReportsSavedFoodItem = "";
public static ArrayList<String> arrFoodItems = new ArrayList<String>();
}
public class ReportsContentActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View contentView = LayoutInflater.from(getParent()).inflate(R.layout.reports_content, null);
setContentView(contentView);
AJ_Constant.arrFoodItems.add("Sample"); }}
thanks
Visit http://android-er.blogspot.in/2011/01/example-of-using-sharedpreferencesedito.html
you can save your data by creating shared preferences.
you can have a look here. there are samples how to use SharedPreferences

What is a general outline for graphics programming on Android?

I'm familiar with Java but am just starting out Android programming, and don't really know what I need to make things happen. I'm trying to work with a Canvas, I'm basically making an app that reads real-time data and makes a constantly changing graph based off of it, with some buttons and other interactive UI. What are the methods I need to implement? For example, in "regular" Java, I know I would NEED to have
public void init(){//...}
public void paint(Graphics g) {//...}
public void run(){//...}
public static void main (String argv[]) {//...}
//...and more
Based on sample code that I found it seems like I need the following general outline (plus my own miscellaneous functions and classes).
public class MyClass extends Activity{
public void onCreate(Bundle savedInstanceState){//initialization and setup}
public class MySurfaceView extends SurfaceView implements Runnable{
public MySurfaceView(Context context){//constructor}
public void onResumeMySurfaceView(){//???}
public void onPauseMySurfaceView(){//deal with user leaving the activity}
public void run(){//...}
public boolean onTouchEvent(){//...}
}
}
Do I need all of these? What more/else do I need? And, what goes in each of the methods (e.g., where does the stuff I would normally put in paint(Graphics g) go)?
I realize this is a very general question that's kind of big, and would appreciate either tips or a link to a tutorial that is more specific than, say, http://developer.android.com/reference/android/app/Activity.html
http://www.amazon.com/Hello-Android-Introducing-Development-Programmers/dp/1934356565/ref=sr_1_1?ie=UTF8&qid=1309211182&sr=8-1
I would suggest getting a good book like the one above.

Categories

Resources