android-context

Expanding in Context in a ListView - Android

无人久伴 提交于 2019-12-04 21:39:13
I have a listView, one component of the row is a TextView. By default, I wish to show only 2 rows of text in the TextView. But if the user taps on the TextView I wanted to the textView to expand in context. I actually have this portion working, but I want to have a more content indicator : My current implementation (Below) has it's own issues w/ not collapsing if the list view is scrolled, but I will handle that by storing the values for each cursor record in some collection.. I tried using chatBubble.getLineCount() but that returns zero initially b/c it has not gone through onLayout (from my

How to provide Context to call necessary functions in my own utility class

风格不统一 提交于 2019-12-04 18:29:14
Sometimes I need to provide a Context object to call specific functions, such as Intent intent = new Intent(context, MyClass.class); in order to start a service context.startService(intent); Or, provide a Context object to do a query Cursor cursor = context.managedQuery(uri, projection, null, null, null); If this is done in a UI class which extends Activity, that's fine. However, If I want to create my own utility class (a singleton) that doesn't extend anything and call these functions, I don't have necessary Context object. Now my workaround is to pass an activity reference while

Android getWritableDatabase() throws a NullPointerException

时光总嘲笑我的痴心妄想 提交于 2019-12-04 18:20:45
I am having trouble with my call to getWritableDatabase(). It is returning a NullPointerException. The thing that is strangest is that this error only began occurring after I commented out a couple lines of code in my android manifest. Now the project is back to where it was (I un-commented those sections and it still throws a NullPointerException). So I checked my context and tried this.getBaseContext() and this.getApplicationContext(). Using getApplicationContext() puts this out to logcat: 08-12 09:24:20.042: E/AndroidRuntime(5572): FATAL EXCEPTION: main 08-12 09:24:20.042: E/AndroidRuntime

Kotlin Android Fragment recyclerView and context issue

老子叫甜甜 提交于 2019-12-04 16:38:33
I would like to create an recyclerView in a fragment, but it shows an error " java.lang.IllegalStateException: recylerView_Main must not be null at com.gph.bottomnavigation.FragmentMe.onCreateView(FragmentMe.kt:28)" Question 1) Please kindly help to solve this issue. Question 2) I created an recyclerView only in a empty project without any fragment, it is working properly. But the same code is no working in Fragment, it shows error so I change "recylerView_Main.layoutManager = LinearLayoutManager(this)" to "recylerView_Main.layoutManager = LinearLayoutManager(context)" It shows no error and I

Android Context without being in an activity? And other activity-less programming?

旧时模样 提交于 2019-12-04 16:25:27
问题 I'll try really hard to turn this into one comprehensive question: I'm writing a method to get a String that contains the name of an Android device's city, as determined by the LocationManager and getLastKnownLocation() and all that. Then I realized I'd need to do the same thing again in another activity, so why not just make an entirely separate class ( LocationFinder ) that I could use across my program, instead of writing duplicate code everywhere? But I've run into problems that confuses

Passing context to Handler

岁酱吖の 提交于 2019-12-04 09:52:28
Is it possible to pass arguments to an Android Handler?? I have two pieces of code. new Thread(){ public void run(){ for(;;){ uiCallback.sendEmptyMessage(0); Thread.sleep(2000); //sleep for 2 seconds } } }.start(); private Handler uiCallback = new Handler(){ public void handleMessage(Message msg){ //add a new blossom to the blossom ArrayList!! blossomArrayList.add(new Blossom(context, R.drawable.blossom)); } }; I of course get an error because the Handler method cannot see my context. This is probably because of this piece of code public BoardView(Context context){ super(context); Context is

Android calling IntentService class from a Service Class

旧巷老猫 提交于 2019-12-04 06:32:32
问题 Can we call IntentService class from a running Service class . Intent myintentservice = new Intent(this, MyIntentService.class); startService(myintentservice); I using above lines of code in service class to start IntentService class. But then I get following error:- Process: objectdistance.ankeshkjaisansaria.ram.sita.cameratag, PID: 21823 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference at

Android code starting from ContentProvider class rather than Main class

戏子无情 提交于 2019-12-04 06:15:26
问题 Yesterday I posted a similar question on why my code started on my content provider class rather than the main class and I've gotten some feedback which I've updated but the problem still remains where the code starts with the ContentProvider class rather than the main class. I've run through the code with debugger and its puzzling why the code starts in the Content Provider and passes back to the main class at the Context stage. I hope to solicit some help here ! The main class is here:

Calling method of another class using contexts

℡╲_俬逩灬. 提交于 2019-12-04 04:03:29
I have a custom titlebar with an ImageButton, which produces a dialogbox, and I want to be able to show location(place itemizedOverlay) on a map(in another class) when list item is selected from dialog box, and titlebar and map are in the same context. I read somewhere that I could call a method of another class using contexts. How can I do so? public class MyTitleBar extends RelativeLayout{ private Context context; public MyTitleBar(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; } @Override protected void onFinishInflate() { super.onFinishInflate();

Why Context can't be used in doInBackground() of AsyncTask

冷暖自知 提交于 2019-12-04 03:58:23
问题 I am just finding what is the fact behind not using Context inside doInBackground() . In-fact we can't update the UI inside doInBackground() directly, to update the UI inside doInBackground() we have to call other thread via publishProgress() method which is responsible to call onProgressUpdate() . So in short I just wanted to know what is the chemistry between UI thread and AsyncTask , and why AsyncTask execute in UI Thread. 回答1: Q Why Context can't be used in doInBackground() of AsyncTask?