I have a UIScrollview of buttons and each time I click one of them i change its backgrund, image and label. It was working fine until today it crashes and it say unrecognized selector. When I NSLog my buttons i can see the second time the are not anymore buttons but UIImageViews.

How the hell can that happen ?

the code is very big but this is the problem part

for (int j = 100; j<[[Utils categoriesName] count]+100; j++)
{
    UIButton *clickedButton = (UIButton *)[self.view viewWithTag:j];
    UILabel *clickedLabel = (UILabel *)[self.view viewWithTag:j+100];
    NSLog(@"%@  \n%@\n\n",clicked Button, clickedLabel);
    [clickedButton setImage:[UIImage imageNamed:[[Utils categoriesIconLight] objectAtIndex:(j-100)]] forState:UIControlStateNormal];
    [clickedButton setImage:[UIImage imageNamed:[[Utils categoriesIconLight] objectAtIndex:(j-100)]] forState:UIControlStateHighlighted];
    [clickedLabel setTextColor:[UIColor whiteColor]];
    [clickedButton setBackgroundImage:[UIImage imageNamed:@"category-button-background"] forState:UIControlStateNormal];
    [clickedButton setBackgroundImage:[UIImage imageNamed:@"category-button-background-selected"] forState:UIControlStateHighlighted];
    [clickedButton setBackgroundColor:[UIColor clearColor]];
}

the second time this loop is run clickedButton and clickedLabel are both UIImageViews

In this iOS 8 app I'm creating, I have a tableview and I need them to be self resizing. I implemented it using Auto Layout and it works. Almost. Here's how it looks now.

enter image description here

There are 3 labels inside a cell. Main label which has the lorem ipsum text. Subtitle which has the string of numbers (Those are two separate labels. Might be confusing because they have the same color.) Then the third label with the small black text.

The first label resized itself correctly with no problem and the second label moves up and down accordingly. But the problem is with the third small label. As you can see, its not resizing itself to fit all the text.

Now there's a weird thing happening. I turn it landscape and here's it is.

enter image description here

Since there is space the label is displaying the entire text its supposed to. Fine. Then I turn it back to portrait.

enter image description here

Now the small label has resized itself to fit all its text but it overflows the cells boundaries. I tried making the cell bigger but it didn't work. Since this is self sizing cells, I don't think that's the correct way even.

I'm not getting any errors or even warning on my auto layout constraints either.

enter image description here

I have set these two lines of code in the viewDidLoad() method.

tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableViewAutomaticDimension

Can anyone please tell me what I might be doing wrong here?

Since its difficult to answer just by looking at images and I don't have any more code to post beside the above snippet, I uploaded a runnable Xcode project demonstrating the issue here. (There are 2 custom cells. Basically its the same cell just the height is increased in the second one.)

I've been fiddling with auto layout constraints but I can't seem to get this working. Any help would be appreciated.

Thank you.

i have a problem with the IME of phone, Whenever i click on an edit Text, and so KeyBoardLifts up, every ListView in my Activity refreshes itself, I could Prevent the app View being Lifted Up EveryTime With KeyBoar, Using a Straight Height to the Layer, But Still They Refresh Themselves, i have these parameters on my MainActivity :

            android:windowSoftInputMode="adjustPan"
            android:launchMode="singleTop"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:screenOrientation="sensor"

and here is my EditText :

 <LinearLayout
        android:id="@+id/bottom_write_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/message_bar" >

        <EditText
            android:id="@+id/TextFeild"
            android:layout_width="0dip"
            android:layout_height="45dp"
            android:layout_margin="5sp"
            android:layout_weight="0.13"
            android:background="@drawable/message_field"
            android:ems="10"
            android:hint="Write here"
            android:padding="5sp"
            android:textColor="@color/textFieldColor" >

            <requestFocus />
        </EditText>

This Refreshes Cause my App to Throw StackOverFlowException :

   09-20 08:15:23.519: E/AndroidRuntime(8223): FATAL EXCEPTION: main
   09-20 08:15:23.519: E/AndroidRuntime(8223): java.lang.StackOverflowError
   09-20 08:15:23.519: E/AndroidRuntime(8223):  at 
   android.view.View.resolveTextDirection(View.java:13939)
   09-20 08:15:23.519: E/AndroidRuntime(8223):  at   
   android.view.View.getResolvedTextDirection(View.java:13923)
   09-20 08:15:23.519: E/AndroidRuntime(8223):  at 
   android.view.View.resolveTextDirection(View.java:13939)

How can i Prevent MyListView's being Refresh by Just KeyBoard Lifting Up?!

enter image description here

In this image, circle is static one. Rectangle image is in behind of this circle. I need to move,zoom out, zoom in and pan the rectangle image within this circle. How to achieve this?

Give me suggestions how to do this.

Thanks in advance

Im thinking of having an android app that has a count down timer. However, i need this timer to be running too even if the user kills the app and once the count down timer reaches 00:00:00, it triggers an action regardless of the application being active. Is there a possible solution to that?

i try to invoke notifyDataSetChange() to redraw the data in the ArrayAdapter, but the whole data in the ArrayAdapter will be redrawn twice.

Here is how i initialise the ListView and ArrayAdapter:

 resultiew = (ListView) findViewById(R.id.result_list);
        this.myadp = new myAdapter(this, android.R.layout.simple_list_item_1,
                results);
        resultiew.setAdapter(myadp);

        // render result
        resultChangeListener();

resultChangeListerner() is a thread that used to call notifyDataSetChange() when the data that should be draw is updated, here is the code:

private void resultChangeListener() {
    new Thread() {
        public void run() {
            while (true) {
                try {
                    if (SearchActivity.listModified == true) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                SearchActivity.listModified = false;

                                resetInfos();
                                Log.e("change search location result",
                                        "there");
                                System.out.println("adapter size:"
                                        + myadp.list.size());
                                myadp.notifyDataSetChanged();
                                System.out.println("listview count: "
                                        + resultiew.getCount());
                            }
                        });
                    }
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}

SearchActivity.listModified indicates where the data is updated.

Below is my ArrayAdapter:

private class myAdapter extends ArrayAdapter<String> {
        public myAdapter(Context context, int resource, List<String> objects) {
            super(context, resource, objects);
            this.list = objects;
        }

        View row;

        private List<String> list;

        public View getView(int position, View convertView, ViewGroup parent) {
            {
                String rowMetaContent[] = this.list.get(position).split(
                        SearchActivity.delimiter);

                LayoutInflater inflater = getLayoutInflater();

                row = inflater.inflate(R.layout.search_results_row_layout,
                        parent, false);

                if (position == 0) {
                    TextView headerTours = (TextView) row
                            .findViewById(R.id.Tours);
                    TextView headerAuthors = (TextView) row
                            .findViewById(R.id.Authors);
                    setHeaderStyle(headerTours, "Tours");
                    setHeaderStyle(headerAuthors, "Authors");

                }

                else {
                    try {

                        TextView headerTours = (TextView) row
                                .findViewById(R.id.Tours);
                        TextView headerAuthors = (TextView) row
                                .findViewById(R.id.Authors);

                        switch (rowMetaContent.length) {
                        case 7:
                            headerTours.setPadding(4, 16, 1, 16);
                            headerTours.setTextColor(Color.BLACK);

                            this.setTextStyle(headerTours, rowMetaContent[0]);
                            keyWordSearchTours.add(rowMetaContent[2]);
                            toursTextViews.add(headerTours);
                            headerTours.setOnClickListener(onclicklistener);

                            headerAuthors.setPadding(4, 16, 1, 16);
                            headerAuthors.setTextColor(Color.BLACK);
                            authorsTextViews.add(headerAuthors);
                            headerAuthors.setOnClickListener(onclicklistener);

                            this.setTextStyle(headerAuthors, rowMetaContent[4]);
                            break;
                        case 4:
                            headerTours.setPadding(4, 16, 1, 16);
                            headerTours.setTextColor(Color.BLACK);
                            this.setTextStyle(headerTours, rowMetaContent[0]);
                            keyWordSearchTours.add(rowMetaContent[2]);
                            toursTextViews.add(headerTours);
                            headerTours.setOnClickListener(onclicklistener);

                            headerAuthors.setPadding(4, 16, 1, 16);
                            headerAuthors.setTextColor(Color.BLACK);
                            break;

                        default:
                            headerTours.setPadding(4, 16, 1, 16);
                            headerTours.setTextColor(Color.BLACK);
                            // this.setTextStyle(headerTours, "");
                            keyWordSearchTours.add("");

                            headerAuthors.setPadding(4, 16, 1, 16);
                            headerAuthors.setTextColor(Color.BLACK);
                            this.setTextStyle(headerAuthors, rowMetaContent[0]);
                            authorsTextViews.add(headerAuthors);
                            headerAuthors.setOnClickListener(onclicklistener);
                            break;

                        }

                         System.out.println(this.list.get(position));
                         System.out.println(list.size());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                return row;
            }
        }

        public void setHeaderStyle(TextView textView, String header) {
            textView.setBackgroundResource(R.layout.customshape_header);
            textView.setPadding(4, 2, 1, 1);
            row.setEnabled(false);
            textView.setEnabled(false);

            textView.setTextColor(Color.BLACK);
            textView.setText(header);

        }

        public void setTextStyle(TextView textView, String result) {
            try {

                // replace all * in result
                String partString[] = result.split("\\$");
                String newResult = partString[0];
                int start = Integer.parseInt(partString[1]);
                int end = Integer.parseInt(partString[2]);
                final SpannableStringBuilder sb = new SpannableStringBuilder(
                        newResult);

                final ForegroundColorSpan fcs = new ForegroundColorSpan(
                        Color.rgb(255, 97, 0));
                final StyleSpan bss = new StyleSpan(
                        android.graphics.Typeface.BOLD);

                sb.setSpan(fcs, start, end + 1,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                sb.setSpan(bss, start, end + 1,
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                // make them also bold
                textView.setText(sb);
            } catch (Exception e) {
                System.out.println("error:  " + result);
                Log.d("exception error", e.toString());
            }

        }
    }





09-20 12:01:21.950: I/System.out(19312): adapter size:3
09-20 12:01:21.980: I/System.out(19312): josh's tour1$0$3###@@@Content###@@@josh-1410695945754###@@@Tours###@@@josh$0$3###@@@Content###@@@Authors
09-20 12:01:21.980: I/System.out(19312): 3
09-20 12:01:21.990: I/System.out(19312): joshua's tour$0$3###@@@Content###@@@joshua's_tour-1409049012110###@@@Tours###@@@joshua$0$3###@@@Content###@@@Authors
09-20 12:01:21.990: I/System.out(19312): 3
09-20 12:01:22.000: I/System.out(19312): joshua's tour$0$3###@@@Content###@@@joshua's_tour-1408968854379###@@@Tours###@@@joshua$0$3###@@@Content###@@@Authors
09-20 12:01:22.000: I/System.out(19312): 3
09-20 12:01:22.010: I/System.out(19312): josh's tour1$0$3###@@@Content###@@@josh-1410695945754###@@@Tours###@@@josh$0$3###@@@Content###@@@Authors
09-20 12:01:22.010: I/System.out(19312): 3
09-20 12:01:22.010: I/System.out(19312): joshua's tour$0$3###@@@Content###@@@joshua's_tour-1409049012110###@@@Tours###@@@joshua$0$3###@@@Content###@@@Authors
09-20 12:01:22.010: I/System.out(19312): 3
09-20 12:01:22.020: I/System.out(19312): joshua's tour$0$3###@@@Content###@@@joshua's_tour-1408968854379###@@@Tours###@@@joshua$0$3###@@@Content###@@@Authors
09-20 12:01:22.020: I/System.out(19312): 3

Here is the output from LogCat, the list size in ArrayAdapter is 3, but the getView() is called 6 times.

I have a sample code that i made for my custom navigation drawer. I don't know how can i add icons to every item position in the listview. The position indicates an intent in order to link the current page to another.I also put string items in an array named data so that i can add it via adapter. The listview is navList Please help!

public class HomePatient extends Activity {
final String[] data ={"Home","Health Progress","Diet","Workout","Medications","Help","Settings","Logout"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.homepatient);

final DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
    final ListView navList = (ListView) findViewById(R.id.left_drawer);


ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
    navList.setAdapter(adapter);
    ArrayAdapter<String> adaptertext = new ArrayAdapter<String>(HomePatient.this, R.layout.textholder, data);
    navList.setAdapter(adaptertext);

        navList.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                String text = data[position];
                if(position==1)
                {
                    Intent i = new Intent(HomePatient.this, HealthProgress.class);
                    i.putExtra("TEXT", text);
                    startActivity(i);
                    //onDestroy();
                    finish();
                }
                if(position==2)
                {
                    Intent i = new Intent(HomePatient.this, DietPatient.class);
                    i.putExtra("TEXT", text);
                    startActivity(i);
                    //onDestroy();
                    finish();
                }
                if(position==3)
                {
                    //Intent i = new Intent(HomePatient.this, WorkoutPatient.class);
                    //i.putExtra("TEXT", text);
                   // startActivity(i);
                    //onDestroy();
                    //finish();
                }
                if(position==4)
                {
                    Intent i = new Intent(HomePatient.this, TreatmentPatient.class);
                    i.putExtra("TEXT", text);
                    startActivity(i);
                   // onDestroy();
                    finish();
                }
                if(position==7)
                {
                    Intent i = new Intent(HomePatient.this, PatientLogin.class);
                    i.putExtra("TEXT", text);
                    startActivity(i);
                    //onDestroy();
                    finish();
                }

            }
});

I'm thinking about developing this app for my academic project. I have never created an android app before, but I have plenty of time to learn. I think translating voice to text is fairly easy I've seen some tutorials on that. Can I show the translated hand gestures in simple 3d animation like a 3d model showing face and hands, using something like unity 3d? If I am using an engine like unity3d or unreal engine can I integrate android's voice recognition feature into it and get what I want? Is there a good way in your opinion to do this?

I'm using Universal Image Loader and I have to load 17 images from this page http://www.mangareader.net/detective-conan/898 then display it into ViewPager. However, images load very slow so I want to reduce the image quality and size for performance. What should I do to improve the speed? Thanks.

how do I change the row griview automatically after loader call method onLoadFinished, when applying LoaderCallbacks in android costume, whose function is equivalent to the method setListShown / setListShownNoAnimation in listview.

I want to support .ts video on my android video player. I tried with standard media player but it can not get duration time of video. getDuration() method always returns 0. I tried with MxPlayer it also could not get duration time. However other players like DicePlayer got it(how?). I discovered that there is Program Association Table (PAT) and it keeps info about transport stream (.ts video formats) . I'm wondering is it possible to get PAT info on android.

Any help kindly appreciated. Thanks in advance.

I want to display logo in place of application icon. At the same time i would also like to have navigation drawer in my app. Is it possible? I tried doing it but When i set logo the navigation drawer didn't show up. I am using AppCompat library and testing it on device running android version of 2.3 .

I now have several view in an app. A lot of views have a pull-up menu, I don't want implement it in every view controller, so I created a view controller whose name is viewWithMenuViewController, every other view inherited from this super view.

How ever at the same time, because every view has the same element(This pull up menu and other's), I don't want put the same pull up view in every view in storyboard either,Assuming I have a view controller with the pull up view in story board file which contains the pull up view and other common elements for every view, what can I do to show this pull up menu in every view whose view controller inherited from the super view controller: viewWithMenuViewController?

Thank you very much for your help guys.

So I get/parse JSON in my viewDidLoad() function so it looks like this

var items = [[String:String]()]

override func viewDidLoad() {
   // getting JSON code
   println(self.items.count) // returns the number of JSON objects eg. 8
}

and then

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return items.count
}

I am getting just one row because it seems like tableView() gets executed before the JSON call is complete.

How can I wait until the request is done and then build my tableView based on what I got in that request?

Or in other words -- what features (from user perspective) a parser have to have to be GLR parser?

It has to be LR, quite obviously, but when it comes to G -- is it sufficient that parses let the forking on reduce/reduce (or shift/reduce) conflict?

I had a strange-feeling pattern come up in some code I was writing. In a project with user accounts, there was a lot of code that needed to do common things such as creating accounts, deleting them, logging them in and out, extending their logged-in session, etc. etc. etc. Now when I was first writing this, I just threw all those responsibilities into one class (which was horrible I know). When it was time to clean this up, I ended up going with an approach that felt right but also strange.

I set up an AccountAccessor class which held private functions for getting the data transfer objects associated with an account, then I made several "action" classes that each would do one thing with access to an account, letting me write:

new AccountPasswordSetter(new AccountAccessor(username)).SetPassword(password);

This felt wrong, because

  1. The action classes were very, very tightly coupled with the AccountAccessor class - there was no hope of testing them
  2. The AccountAccessor class would have to expose it's data access functions for the action classes to use them.
  3. I have to expose construction of the action classes to the client code. This felt problematic because really, there's no sensible reason anything outside the project needs to concern itself with their instantiation.
  4. Each of the action classes only needed one of the data transfer objects the AccountAccessor provided - for example an action class responsible for logging the user out doesn't need access to the account's password.
  5. Writing this feels very wordy and "inside out".

What I ended up doing instead was I made the action classes all able to be constructed only inside the project, and instead of needing an AccountAccessor I had them set up to simply accept a function that would take a connection to the database and return the one particular DTO they needed. Then, when the account accessor was constructed, would would create a whole slew of these action objects and pass each of them one of it's private methods for getting the DTO. Something like:

public class AccountAccessor {
    public AccountPasswordSetter PasswordSetter { get; private set; }
    public AccountSessionExtender SessionExtender { get; private set; }
    public string Username { get; private set; }

    public AccountAccessor(string username) {
        Username = username;
        PasswordSetter = new PasswordSetter(getPasswordEntity);
        SessionExtender = new SessionExtender(getSessionEntity);
    }

    private PasswordEntity getPasswordEntity(Connection databaseConnection) { ... }
    private SessionEntity getSessionEntity(Connection databaseConnection) { ... }
}

Now, client code can simply call something like:

new AccountAccessor(username).PasswordSetter.Set(password)`

The responsibilities are split up, and the action classes don't have to know or care about what an AccountAccessor is. The client code doesn't have to know or care about how the various objects that provide functionality are set up. The AccountAccessor only selectively exposes access to the database entities. This felt much, much better. What I liked most about this design was it solved a lot of the problems I was having without imposing any architectural headaches on the client code. If client code wants to log out an account and delete it, they just get an accessor then log it out and delete it – no need to work out how to properly pass objects around. The obvious approach for the client code just works.

But it still seems a little off – passing private methods as arguments to other objects comes across as fundamentally strange to me. I wanted to know more about what sort of problems this has, and what I should keep in mind when designing things fitting this sort of scenario in the future.

When designing an interface for passing objects which are meant to be stored for later use and which should not be 'null', I am always a bit uncertain if the argument should be passed by reference or as a pointer.

This is an example of what I mean:

class Foo
{
private:
    Bar* m_bar;

public:
    Foo() : m_bar(nullptr)
    {
    }

    void Register(Bar& bar)
    {
        m_bar = &bar;
        m_bar->Registered();
    }
    // -- OR --
    void Register(Bar* const bar)
    {
        if (bar == nullptr)
        {
            // Error!
        }

        m_bar = bar;
        m_bar->Registered();
    }

    // Some method makes use of the stored pointer later
    void DoSomething()
    {
        if (m_bar == nullptr)
        {
            // Error!
        }

        m_bar->DoOtherThing();
    }
};

My thoughts on this are:

  1. The passed in reference may go out of scope before DoSomething gets called, but that may happen with the pointed to object as well.
  2. Using the pass-by-non-const-reference version gets rid of duplicating the check for null and tells the caller that it is not possible to register 'nothing'.
  3. It would be better to pass a reference in the constructor of Foo as it is required by DoSomething, but sometimes it this is not an option.
  4. It would be better to pass a reference to DoSomething directly, but again, this is not always possible.

So if I need that kind of separate setter/register method, would it be clearer to use a reference or a pointer?

PS I know there is are two very similar questions Storing a pass-by-reference parameter as a pointer - Bad practice? and Reference vs dereference pointers in arguments C++/C, but I think they both are concerned with slightly different problems. The former deals mostly with the (ab)use of const and the latter does not say anything about storing a pointer. There may be another question/answer out there, if so, please just mark this a duplicate then!

What does it mean if a employer asks if you have working knowledge of HTML, CSS, JavaScript, C# and SQL Server?

Most of it was written 4-5 years ago. Our teams long term objectives are to use Entity Framework. Though we aren't gonna do it right away as our deadlines aren't allowing us to do so. Now we have our own framework. I want to be able to segregate the Business logic layer in such a way that it need not be re-written when we move to EF. Please guide us with best practices, advise us in this direction.

Our business logic layer is very fragmented today (UI Code Behind + Stored Procedures/functions SqlServer/ C# persistent classes) : What if I want to segregate it totally and draw a very prominent line between Storage | DAL | Business Logic | UI

  1. I want to know if it's ok to move the BLL totally in SQl stored Procedures or does it have to be totally C# classes?

  2. Also to avoid re-writing the BLL as we are going to move to EF eventually. What steps should I take so that I can readily use the entire BLL with EF without changing the code.

  3. A lot of the stored procedures (which have the BL) lie in the storage DB itself. Does segregating the BLL mean the SP's and functions should be in a different database altogether? or for all practical purposes it's ok for them to be in the same DB?

I've seen multiple questions on SO which were really helpful, but I just couldn't get a clear picture of the solution or advise I seek, so I put everything in one post.

Please correct me if I'm wrong. I'm a novice when it comes to system design. I wanna be able to foresee what I'm getting into before actually implementing it.

By reading the traditional Taligent paper, I can't find a definite answer to what they mean by Selection. The selection could be just a set of indices referring to entries in the Model, so that a Command can act on the proper Model subset, but what is not clear from the Paper is how they represent this selection in the View.

There are two possibilities to this:

  • either they assumed that all visual selection representation is handled by the View, and the selection they talk about is nothing but a "set of indices" object that is extracted from the View by the Presenter and fed to the Command.
  • or the selection is an actual Selection Model, and as such must be made available to the View so that it can inquire about it for visual representation (e.g. a User action "Select all" modifies the Selection Model, which notifies the View to highlight all the items). However, from the paper, this connection between the selection and the View is not present.

How is Taligent MVP formally supposed to handle a Selection's visual presentation?

Is there any situation where it makes sense to define a python property, where getting (not setting) it would raise an exception? I don't think this ever happens for fields in classes, hence the question.

Or is always better in these cases to use a method instead?